Difference between revisions of "Setting Unix environment variables for GEOS-Chem"

From Geos-chem
Jump to: navigation, search
(Errors caused by incorrect environment variable settings)
m (Minor typo correction)
Line 143: Line 143:
 
Then make sure to type:
 
Then make sure to type:
  
  source ~./bashrc  # if you are using bash
+
  source ~/.bashrc  # if you are using bash
 
  source ~/.cshrc    # if you are using csh or tcsh
 
  source ~/.cshrc    # if you are using csh or tcsh
  

Revision as of 11:21, 14 June 2017

This page contains information about how to set several environment variables in your Unix environment that are needed to compile GEOS-Chem.

Environment variables that specify compiler names

GEOS-Chem currently supports the Intel Fortran compiler (ifort), the GNU Fortran compiler (gfortran), and the PGI Fortran compiler (pgfortran or pgf90). You must set the following variables in your Unix environment to tell GEOS-Chem which compiler type you are using.

Variable Description
FC Name of the Fortran compiler
CC Name of the C compiler.
Not needed for GEOS-Chem, but this may be required to build other software packages (such as the netCDF libraries).
FC Name of the C++ compiler.
Not needed for GEOS-Chem, but this may be required to build other software packages (such as the netCDF libraries).
COMPILER This should be set to the same value as FC.
In v11-02a and higher versions, the dependence on the COMPILER environment variable will be removed.

On many systems (such as the Harvard Odyssey cluster), FC, CC, and CXX will be set automatically for you when you load a software module into your Unix environment with the module load command. The easiest way to check if these variables have been automatically set for you is to print them to the screen. Type at the Unix prompt:

echo $FC
echo $CC
echo $CXX

If FC, CC, and CXX are not blank, then that means that they have been automatically set for you. The only remaining thing that you have to do is to add the following line to your system startup file to define the COMPILER environment variable.

If your
shell is
add to
this file
the following lines of code
/bin/bash .bashrc. export COMPILER=$FC
/bin/csh or
/bin/tcsh
.cshrc setenv COMPILER $FC

On the other hand, if FC, CC, and CXX are all undefined, then you will have to manually set them in your startup script, as described in the table below:

If your
shell is
and your
compiler is
add to
this file
the following lines of code
/bin/bash ifort .bashrc
export FC=ifort
export CC=icc
export CXX=icpc
export COMPILER=$FC
/bin/bash gfortran .bashrc
export FC=gfortran
export CC=gcc
export CXX=g++
export COMPILER=$FC
/bin/bash pgfortran .bashrc
export FC=pgfortran
export CC=pgcc
export CXX=pgc++
export COMPILER=$FC
/bin/bash pgf90 .bashrc
export FC=pgf90
export CC=pgcc
export CXX=pg++
export COMPILER=$FC
/bin/csh or
/bin/tcsh
ifort .cshrc
setenv FC ifort
setenv CC icc
setenv CXX icpc
setenv COMPILER $FC
/bin/csh or
/bin/tcsh
gfortran .cshrc
setenv FC gfortran
setenv CC gcc
setenv CXX g++
setenv COMPILER $FC
/bin/csh or
/bin/tcsh
pgfortran .cshrc
setenv FC pgfortran
setenv CC pgcc
setenv CXX pg++
setenv COMPILER $FC
/bin/csh or
/bin/tcsh
pgf90 .cshrc
setenv FC pgf90
setenv CC pgcc
setenv CXX pg++
setenv COMPILER $FC

Then make sure to type:

source ~/.bashrc   # if you are using bash
source ~/.cshrc    # if you are using csh or tcsh

to apply the changes.

--Bob Yantosca (talk) 16:37, 10 March 2017 (UTC)

Environment variables that specify library paths

The following sections describe how to define environment variables that point to the netCDF etc. library paths on your system.

GEOS-Chem

GEOS-Chem uses the netCDF library for file I/O. You should first check to see if there is a pre-built netCDF library installation on your system already. If not, then you (or your IT staff) can install GEOS-Chem with our GEOS-Chem library installation package.

After you have verified that a netCDF library installation exists on your system, the next step is to tell GEOS-Chem where to find the relevant library, include, and executable files. Otherwise you will get errors during the compilation process. The easiest way to do this is to set environment variables in your setup files:

  1. .bashrc : if you use Bourne-Again shell (bash)
  2. .cshrc  : if you use C-shell (csh) or T-shell (tcsh)

There are three environment variables that you need to set:

Variable Description
GC_BIN Points to the bin/ subfolder of the root netCDF path. This is where the nc-config and nf-config files are located.
GC_INCLUDE Points to the include/ subfolder of the root netCDF path. This is where netCDF include files (*.h, *.inc) and compiled module files (*.mod) for the netCDF (and HDF5) libraries are located.
GC_LIB Points to the lib/ subfolder of the root netCDF path. (On some systems this may be named lib64/ instead.) This is where the netCDF library files (*.a) are located.

If (and only if) you loaded the netCDF Fortran library as a separate module (e.g. for netCDF-4.2 and higher versions), you will also need to set these variables:

Variable Description
GC_F_BIN Points to the bin/ subfolder of the root netCDF Fortran path. This is where the nf-config file is located.
GC_F_INCLUDE Points to the include/ subfolder of the root netCDF Fortran path. This is where netCDF include files (*.h) and compiled module files (*.mod) are located.
GC_F_LIB Points to the lib/ subfolder of the root netCDF Fortran path. (On some systems this may be named lib64/ instead.) This is where the netCDF library files (*.a) are located.

The best way to define these variables is to add them to your .bashrc (or .cshrc) system startup file.

We recommend using the NETCDF_HOME etc. variables that are defined by the module load command to define the environment variables needed for GEOS-Chem. If you built the netCDF libraries with our netCDF installer package, then you can just define the GEOS-Chem environment variables manually, e.g.:

# Tell GEOS-Chem where to find netCDF library files
export GC_BIN=/YOURPATH/ifort/nc4/bin
export_GC_INCLUDE=/YOURPATH/ifort/nc4/include
export GC_LIB=/YOURPATH/ifort/nc4/lib

If you have any questions about where the library paths for netCDF are located on your system, ask your IT staff.

With bash

If you use bash, then add the following lines to your .bashrc file:

# Tell GEOS-Chem where to find netCDF library files
export GC_BIN=$NETCDF_HOME/bin
export_GC_INCLUDE=$NETCDF_INCLUDE
export GC_LIB=$NETCDF_LIB

# NOTE: If netCDF-Fortran was loaded as a separate module, then
# also define these variables.  (Otherwise comment these out.)
export GC_F_BIN=$NETCDF_FORTRAN_HOME/bin
export GC_F_INCLUDE=$NETCDF_FORTRAN_INCLUDE
export GC_F_LIB=$NETCDF_FORTRAN_LIB

Then to accept the changes, type source ~/.bashrc at the Unix prompt.

With csh or tcsh

If you use C-shell (csh) or T-shell (tcsh), then add the following lines to your .cshrc file:

# Tell GEOS-Chem where to find netCDF library files
setenv ROOT_LIBRARY_DIR root_library_dir
setenv GC_BIN           $(NETCDF_HOME)/bin
setenv GC_INCLUDE       $(NETCDF_INCLUDE)
setenv GC_LIB           $(NETCDF_LIB)

# NOTE: If netCDF-Fortran was loaded as a separate module, then
# also define these variables.  (Otherwise comment these out.)
setenv GC_F_BIN         $(NETCDF_FORTRAN_HOME)/bin
setenv GC_F_INCLUDE     $(NETCDF_FORTRAN_INCLUDE)
setenv GC_F_LIB         $(NETCDF_FORTRAN_LIB)

where root_library_dir is the directory into which you installed the libraries, as described above. Then to accept the changes, type source ~/.cshrc at the Unix prompt.

--Bob Yantosca (talk) 16:21, 10 March 2017 (UTC)

Other related Fortran software packages

Some related Fortran code packages use slightly different environment variable names than GEOS-Chem does (see above section). Here is a quick list of the differences:

Software package In the same way
you defined these variables:
Also define these variables
in your .bashrc or .cshrc
The NcdfUtilities package
(standalone distribution)
GC_BIN
GC_INCLUDE
GC_LIB

GC_F_BIN
GC_F_INCLUDE
GC_F_LIB
NETCDF_BIN
NETCDF_INCLUDE
NETCDF_LIB

NETCDF_FORTRAN_BIN
NETCDF_FORTRAN_INCLUDE
NETCDF_FORTRAN_LIB
GEOS-FP data processing software
GC_BIN
GC_INCLUDE
GC_LIB

GC_F_BIN
GC_F_INCLUDE
GC_F_LIB
NETCDF_BIN
NETCDF_INCLUDE
NETCDF_LIB

NETCDF_FORTRAN_BIN
NETCDF_FORTRAN_INCLUDE
NETCDF_FORTRAN_LIB

--Bob Yantosca (talk) 20:27, 10 March 2017 (UTC)

Errors caused by incorrect environment variable settings

If you encounter any of the GEOS-Chem errors listed below, please doublecheck your environment variable settings as described in the preceding sections.

  1. f77: command not found

--Bob Yantosca (talk) 17:30, 10 March 2017 (UTC)