MEGAN Installation - adelgadop/WRFCMAQ GitHub Wiki

Megan consists of three parts:

  • prepmegan4cmaq: A bunch of FORTRAN programs to calculate the MEGAN Input files from global files to regional domains setting up to CMAQ. They are all executed in the shell providing a name list for in- and output folders and parameters. Some Datasets are Hardcoded in the FORTRAN code. If you want to alter some data (e.g. LAI data), you must alter the source code and recompile it.
  • MEGAN_EFP32: Scientific preprocessor in Python.
  • src (itself): More sophisticated FORTRAN programs containing the scientific core of MEGAN and the preprocessor for meteorology data and the chemistry mechanism. Every part of MEGAN is its own full FORTRAN program with its run script. At the end, a CMAQ-compatible netCDF file is written.

How to compile

Create a directory mwe_megan in a specific path (~/WRFCMAQv5.4/UTIL/mwe_megan). Download the preprocessor code.

prepmegan4cmaq

MEGAN32_Prep_Code_Jan_2022 has two files (Makefile and make_util). So, we edit the Makefile:

.SUFFIXES: .o .f90                                                                                                  
                                                                                
F90     = ifort #$(FC)                                                           
#LIBS   = -L$(NETCDF_DIR)/lib -lnetcdf                                          
LIBS    = -L$(NETCDF_DIR)/lib -lnetcdff -lnetcdf                                 
INCLUDE_MODULES = -I$(NETCDF_DIR)/include                                       
FFLAGS  = -O3 -Bstatic 

Afterward, you should compile four submodules of prepmega4cmaq, typing the following commands:

./make_util prepmegan4cmaq_lai.x
./make_util prepmegan4cmaq_grwform.x
./make_util prepmegan4cmaq_ecotype.x
./make_util prepmegan4cmaq_cantype.x

MEGAN_EFP

Review this

MEGAN (CORE)

Go to the directory ${yourdirectory}/mwe_megan/megan. Every program here must be compiled. They all depend on netCDF and IOAPI. Some depend on program-specific includes. We edit the make_all_programs.scr:

 source ./setcase.csh
 setenv IOAPI /home/alejandro/BLDLIB/ioapi-3.2
 setenv IOAPI_LIB /home/alejandro/BLDLIB/ioapi-3.2/Linux2_x86_64ifort
 setenv NETCDF_LIB /opt/comp_ifort_2021/netcdf/lib
 setenv NETCDF_INC /opt/comp_ifort_2021/netcdf/include

In addition, we edit the setcase.csh:

 #! /bin/csh
 setenv MGNHOME "/home/alejandro/WRFCMAQv5.4/UTIL/mwe_megan/megan"
 setenv MGNSRC $MGNHOME/src
 setenv MGNRUN $MGNHOME/work

We must copy each makefile.intel as makefile inside each program to compile inside each directory of src. Please write in the terminal cd src. After that, edit the makefile of the directory IOAPI2UAM as follows:

SHELL = /bin/sh
FC = ifort
FFLAGS= -O -Mvect=sse -Mextend -Msecond_underscore -Bstatic_pgi -Mlfs
#FC = ifort
#FFLAGS = -O2 -fp-model precise -fpp -132 -mcmodel=large -convert big_endian
PROGRAM = ioapi2uam
LIBS =   -L/home/alejandro/BLDLIB/ioapi-3.2/Linux2_x86_64ifort/  -lioapi \
         -L/opt/comp_ifort_2021/netcdf/lib -lnetcdff -lnetcdf
INCLUDE = -I/home/alejandro/BLDLIB/ioapi-3.2/ioapi/fixed_src \
          -I/opt/comp_ifort_2021/netcdf/include

After that, return to src and go to TXT2IOAPI to verify/edit the first lines of the makefile as follows:

SHELL=/bin/sh
FC = ifort
#FFLAGS = -O3 -fixed -132 -traceback -xHost -Bstatic
FFLAGS = -check all -fp-stack-check -O3 -g -fixed -132 -traceback -qopenmp -xHost -Bstatic

LIBS =   -L$(IOAPI_LIB) -lioapi \
         -L$(NETCDF_LIB) -lnetcdff -lnetcdf
INCLUDE = -I$(IOAPI)/ioapi/fixed_src \
          -I$(NETCDF_INC) \
          -I$(CURDIR)/INCLDIR
PROGRAM = txt2ioapi

Return to the src directory and edit each makefile of the directories such as DAYMET, MEGCAN, MEGSEA, MEGVEA, MET2MGN, MGN2MECH. For example, the makefile of MEGCAN must have the first lines as follows:

SHELL=/bin/sh
PROGRAM= megcan
FC = ifort
#FFLAGS= -O -Mvect=sse -Mextend -Msecond_underscore -Bstatic_pgi -Mlfs
#FFLAGS = -O3 –fixed -132 -traceback -qopenmp -xHost –Bstatic
FFLAGS = -O3 -fixed -132 -traceback -qopenmp -xHost -Bstatic
LIBS =   -L$(IOAPI_LIB) -lioapi \
         -L$(NETCDF_LIB) -lnetcdff -lnetcdf
INCLUDE = -I$(IOAPI)/ioapi/fixed_src \
          -I$(NETCDF_INC) \
          -I$(CURDIR)/INCLDIR

To compile MEGAN enter:

./make_all_programs.scr 64bit

You can verify inside each directory of src if each program was compiled.