Compiling Geos-Chem

Geos-Chem 8.2.x and earlier

Geos-Chem versions 8.2.x and earlier are compiled via a process different than that described in the Online Geos-Chem manual. Starting in version 3.1.x, the developers chose to use 'Make' for compiling the code, instead of the 'Build' command used by the earlier versions. This document describes how to change the Geos-Chem and compiler options and how to recompile the GC source code.

Source Code Directory

The Fortran source code for Geos-Chem is commonly copied to a subdirectory (typically named 'code') in the user's model directory, as it is a convenient location for making customized changes to the code and for recompiling the executable with different options.

Changing Geos-Chem Options

The file 'define.h' contains all of the C-preprocessor "switches" used to configure the compilation process. Open 'define.h' using your favorite text editor. The key sections that may require editing are:

As an example, let's edit 'define.h' to reconfigure Geos-Chem for the GEOS4 model type and for a 2x2.5 grid size. First, find 'define.h' in the 'code' subdirectory and open it in a text editor. Go to Line 103 and make the following changes for the Model Type. Note that the ! character (exclamation point) in the first position indicates that the line is a comment and is not processed by the compiler.

file: define.h
   103:  !----- Model types -----
   104:  !#define GCAP        'GCAP'
   105:  !#define GEOS_3      'GEOS_3'
   106:  #define GEOS_4      'GEOS_4'
   107:  !#define GEOS_5      'GEOS_5'

Next, go to Line 109 and make the following changes to the Grid Size.

file: define.h
   109:  !----- Grid sizes -----
   110:  !#define NESTED_CH   'NESTED_CH'
   111:  !#define NESTED_NA   'NESTED_NA'
   112:  !#define GRID05x0666 'GRID05x0666'
   113:  !#define GRID1x1     'GRID1x1'
   114:  !#define GRID1x125   'GRID1x125'
   115:  #define GRID2x25    'GRID2x25'
   116:  !#define GRID4x5     'GRID4x5'

It is usually not necessary to change the Fortran compiler, so skip down to Line 127 and comment out the In-Cloud Optical Depth line, as it is not used with any grid size other than 4x5.

file: define.h
   127:  !----- FOR GEOS-5 MET FIELDS ONLY -----
   128:  ! NOTE: If you are using GEOS-5 met fields that were reprocessed to 
   129:  ! correctly regrid the in-cloud optical depth and cloud fraction fields, 
   130:  ! then be sure to uncomment the following line of code.  This will cause 
   131:  ! FAST-J to interpret the optical depth correctly.  Leaving this option
   132:  ! commented will cause a "quick fix" (i.e. multiplying the optical depth
   133:  ! by the cloud fracton) to be applied, which should be a good enough fix
   134:  ! in the meantime. (bmy, hyl, 10/24/08)
   135:  !#define IN_CLOUD_OD  'IN_CLOUD_OD'

Once all of the changes have been made, save the file (do not change the name) and close the file. Now open the file 'Makefile.ifort', which contains the compiler flags for Intel Professional Fortran. Unless it is necessary to change compiler options (for advanced users only!), the only line that might need to be changed is Line 245. Here, you can change the name of the compiled executable file.

file: Makefile.ifort
   245:  #=============================================================================
   246:  #  Executables and Documentation
   247:  #=============================================================================
   248:  geos:   $(MODS) $(OBJS) $(OBJSe) $(FJ)    
   249:  	$(F90)  $(MODS) $(OBJS)  $(OBJSe) $(FJ) -o geos.GEOS4.2x25.v822

After making the change, save the file and close the editor.

The next step is to clean up the old .obj and .o files with the command:

> ./build clean

Then, to recompile the Geos-Chem code and build a new executable, type the command:

> ./build geos

The build process will likely take several minutes. Once complete, the final step is to copy the new executable to your model directory (where 'input.geos' resides). This can be done by typing the following command (actual format will depend on how your model directory is structured):

> cp geos.GEOS4.2x25.v822 ../

Now, go to your model directory and verify that the new executable file is there. If so, edit the 'input.geos' file and get modeling!