# Create Scripts The `create_fates_run.sh` script is a set of instructions specifying the configuration of the FATES run. An example script is found in the fates-tutorial repository under run_scripts (outside the container) or scripts (insdie the container). To run the create script and launch a FATES simualtion, from inside the elm-fates container, change directory to the scripts directory and type: ``` ./create_elm-fates-singlepoint-1pft_bci_invinit.sh ``` In the page below we explain what key parts of the script do. Open `create_elm-fates-singlepoint-1pft_bci_invinit.sh` with your text editor of choice and then see below for details. ``` #!/bin/sh # ======================================================================================= # ======================================================================================= export CIME_MODEL=e3sm export COMPSET=2000_DATM%QIA_ELM%BGC-FATES_SICE_SOCN_SROF_SGLC_SWAV export RES=ELM_USRDAT export MACH=docker # Name your machine export COMPILER=gnu # Name your compiler export SITE=bci # Name your site ``` The first line indicates that this is a shell script. Next is a block of code indicating some model configurations. The CIME model is the infrastructure that allows different model components to communicate, for example, the land model and the atmospheric model. The COMPSET specifies which components are active. Here we will run land only simulations. RES is the model resolution. In a global run this would be the size of each model grid cell. Here we specify that we are running FATES as a single point. MACH is the machine being used. In this case we specify docker since we are running FATES via docker. FATES and the host land model code is written in Fortran which is a compiled language. The COMPILER option specifies which compiler to use. Here we use gnu as this is installed in the docker environment. Finally, SITE is where we tell FATES which site we are going to run the simulation, in this case BCI. We make some variables to use in the rest of the script. ``` export TAG=fates-tutorial-${SITE}-inventory_init # give your run a name export CASE_ROOT=/output/${SITE} # where in scratch should the run go? export PARAM_FILES=/paramfiles # FATES parameter file location ``` The next code block specifies where the surface and domain files needed to run FATES are located. ``` # surface and domain files export SITE_BASE_DIR=/sitedata export ELM_USRDAT_DOMAIN=domain_${SITE}_fates_tutorial.nc export ELM_USRDAT_SURDAT=surfdata_${SITE}_fates_tutorial.nc export ELM_SURFDAT_DIR=${SITE_BASE_DIR}/${SITE} export ELM_DOMAIN_DIR=${SITE_BASE_DIR}/${SITE} export DIN_LOC_ROOT_FORCE=${SITE_BASE_DIR} ``` The surface dataset contains information on the soil properties and the fraction of the grid cell that is natural vegetation. The domain file contains information on the lat and lon of the site and what fraction of the grid cell is active i.e. running FATES. DIN_LOC_ROOT_FORCE forces the model to use climate driving data located within the site directory. Climate data is stored in the sitedata directory. For simulations at new sites we will use GSWP3 reanalysis data that has been subset to only the grid cell of each site. Since this data is only available from the years 2003 to 2014 we tell the model to keep cycling the climate data so that we can run longer simulations. For BCI, we have meterological data from a tower at the site, and we can use this data which is available between 2003 and 2016. ``` # climate data will recycle data between these years export DATM_START=2003 export DATM_STOP=2016 ``` The next code block changes into the directory where the scripts needed to create a FATES case are located. We make a case name by appending today's date to the tag defined above. ``` # DEPENDENT PATHS AND VARIABLES (USER MIGHT CHANGE THESE..) # ======================================================================================= export SOURCE_DIR=/E3SM/cime/scripts # change to the path where your E3SM/cime/sripts is cd ${SOURCE_DIR} export CASE_NAME=${CASE_ROOT}/${TAG}.`date +"%Y-%m-%d"` ``` Within the E3SM/cime/scripts directory is the create_newcase script which we call with arguments defined above to set up the FATES simualtion. When the case has been created we change into the case directory. ``` # REMOVE EXISTING CASE IF PRESENT rm -r ${CASE_NAME} # CREATE THE CASE ./create_newcase --case=${CASE_NAME} --res=${RES} --compset=${COMPSET} --mach=${MACH} --compiler=${COMPILER} --project=${PROJECT} cd ${CASE_NAME} ``` The next two blocks of code can be ignored as they relate to the inner workings of the host land model. The next chunk of code relevant for the tutorial is where we specify run type preferences. ``` # SPECIFY RUN TYPE PREFERENCES (USERS WILL CHANGE THESE) # ================================================================================= ./xmlchange DEBUG=FALSE ./xmlchange STOP_N=10 # how many years should the simulation run ./xmlchange RUN_STARTDATE='1900-01-01' ./xmlchange STOP_OPTION=nyears ./xmlchange REST_N=10 # how often to make restart files ./xmlchange RESUBMIT=0 # how many resubmits ./xmlchange DATM_CLMNCEP_YR_START=${DATM_START} ./xmlchange DATM_CLMNCEP_YR_END=${DATM_STOP} ``` Here we set DEBUG to FALSE as (hopefully) everything should be running smoothly in the tutorial. If you are ever encountering errors when trying to get FATES to compile or run, then setting DEBUG to true might mean you get more informative error messages. STOP_N is how many time steps to run the simulation, with the unit of time specified by STOP_OPTION - in this case years. REST_N specifies how often to write restart files - these are a snapshot of the simulation containing all necessary information on the ecosystem to be able to restart the run from that point. RUN_STARTDATE is fairly arbitrary in this case - we chose 1900 for no particular reason. RESUBMIT is set to 0 here. In very long simulations (decades or centuries) it can help to run FATES in smaller chunks by setting STOP_N to a factor of the total length of the simulation and increasing RESUBMIT such that RESUBMIT x STOP_N equals the total simulation length. The next block of code specifies where to build the case and where to save model outputs. ``` # MACHINE SPECIFIC, AND/OR USER PREFERENCE CHANGES (USERS WILL CHANGE THESE) # ================================================================================= ./xmlchange GMAKE=make ./xmlchange RUNDIR=${CASE_NAME}/run ./xmlchange EXEROOT=${CASE_NAME}/bld ``` The next bit is where we edit the user_nl_elm file. The user_nl_elm file specifies namelist options, such as which optional modules to turn on, and points to the parameter file and inventory data. It also defines which history variables to output. ``` # point to your parameter file # add any history variables you want cat >> user_nl_elm <> user_nl_datm <