The CALPUFF modeling system is suggested for long-range air quality dispersion model of US-EPA and it is used all over the world as reference model for regulatory purposes in all those contexts where a Gaussian moel as AERMOD cannot completely describe the dispersion of pollutants (e.g. complex terrain, non-homogeneous meteorological conditions, calm wind conditions). Exponent distributes the Fortran source code and an executable to be used with Microsoft Windows. In order to compile the distributed source code under Linux and OS X with the free GNU Fortran compiler gfortran it is necessary to make some fixes to the source code, otherwise there is a segmentation fault error that prevents a successful compilation.

This post describes how to install and run the codes part of the CALPUFF modeling system version 5.8.4 on a Mac running OS X 10.9 (Yosemite). It should work with later OS X versions too (e.g. Sierra)

You're responsible for any malfunctioning that the following might cause.

In order to use the US-EPA approved CALPUFF modeling system v 5.8.4 on a Apple computer running OS X Yosemite 10.9 it is necessary to follow these steps:

  1. Install Xcode tools
  2. Install gfortran compiler if not installed yet
  3. Download the CALPUFF modeling system source codes
  4. Modify the source code
  5. Modify the compilation scripts
  6. Compile the codes

Here are the steps in detail.

If Xcode tools are not installed on your Mac, open a terminal and run the command

xcode-select --install

Download and run the dmg installer from the GCC wiki to install gfortran compiler or install via Homebrew.

Visit the US-EPA page dedicated to the CALPUFF modeling system and access the link to the Exponent website for downloading the source codes.

The source code of CALMET, the diagnostic meteorological preprocessor of CALPUFF, is located in folder

CALPUFF_5.8.4/CALMET_v5.8.4/CALMET/CODE

First, there are a couple of changes to be made to the source code, as suggested in the code comments:

- comment the call to the ETIME subroutine, line 2598 of calutils.for and all the lines of the subroutine ETIME, line 2603 and following of calutils.for.

- enable GETARGS call for fortran compiler at line 2722 of calutils.for.
                    

Within the CODE directory a batch file named compile-calmet-gfortran.bat is available for compiling the code with gfortran.

The command provided is:

MyMac:roberto$ cat compile-calmet-gfortran.bat
gfortran -static -o calmet.exe calmet.for 2>compile-calmet-gfortran.log

In order to compile under OS X the -static flag has to be removed.

Also, please note that including the -Wall flag the compilation log shows an error in the implementation of the calculation of the convective PBL over water with Gryning-Batchvarova. This error has been fixed starting from the CALMET v.6.5.0 released in February 2015 and included in the CALPUFF Modeling system version 7 released in June 2015.

The suggested compilation command is thus:

MyMac:roberto$ cat compile-calmet-gfortran.bat
gfortran -o calmet.exe -Wall calmet.for 2>compile-calmet-gfortran.log

This will produce the calmet.exe executable. The same procedure can be followed for compiling CALPUFF.