Skip to content

2. Compilation explanation

jrulent edited this page Feb 6, 2025 · 23 revisions

Introduction

This section contain a more detailed explanation of how the compilation of the coupled model works and guides you through the sections of the setup_Coupled_AMM15_WW3 providing addition information on the coupling.

Script start

The beginning of the setup_Coupled_AMM15_WW3 introduces the script. As the Archer2 helpdesk assisted us with part of this work, some additional resources on the coupling can be found in their nemo-ww3 repository, which is cited in the script.

Notes:

  • the set -e ensures that the script exits immediately if any command fails, preventing from any incorrect execution. The lines echoed in display_usage() will appear on your screen if the function is called before the script exits with an error (exit 1). However, display_usage() does not run automatically; it must be triggered somewhere in the script. Currently, it is not being used, but you can call it if you modify the script, need debugging assistance, or find it useful for handling errors.

  • the #!/bin/bash shebang specifies that the script should be run using the Bash shell.

  • the ${0##*/} just writes the name of the script out.

#!/bin/bash
# Script to set up coupled AMM15-WW3 on  ARCHER2
# Note: architecture files and OASIS configuration files 
# can also be found in the archer2 helpdesk GIT repository:
# https://github.com/EPCCed/ww3-nemo/tree/main
set -e 
display_usage() { 
   echo
   echo "  Auto-Config: AMM15-WW3 on ARCHER2"
   echo "  ***************************************"
   echo
   echo "  usage: ${0##*/} set paths in this file "
   echo
   exit 1
	} 

Set paths

Before running the script you need to amend some of the paths in the section:

#################################################################################################
# set paths - user can amend
#################################################################################################
export CONFIG=COW_360cal
export WORK=/<directory>/<you>/<want>/<to>/<compile>/<in>
export REPO_DIR=$(pwd)/.. #COW_AMM15 repository directory
export WORK_DIR=$WORK/$CONFIG
export XIOS_DIR=$WORK/$CONFIG/xios/
export HPC_TARG=archer2-gnu-r8-d8
export NEMO_SRC=$REPO_DIR/AMM15/MY_SRCs/MY_SRC_360cal/

The only directory you need to set is the WORK directory, which should point to the location where the CONFIG directory will be created. The model will then be compiled inside the CONFIG directory. If you want, you can change the name of the CONFIG directory. The WORK_DIR where everything is compile is the combined path from these two.

Note: If you want to run a second compilation while keeping your original configuration, you can simply change the CONFIG directory and run the script again. The model will be recompiled in the new directory. However, be mindful that repeatedly doing this can lead to multiple copies of files, consuming significant storage space.

The XIOS_DIR is where your xios will be checked out. No need to change that.

The HPC_TARG is the name of a compiler configuration we have worked on with the Archer2 HPC helpdesk (see nemo-ww3). It matches with the name of some of the architecture files used for the compilation (set with "-fdefault-real-8 -fdefault-double-8"). Do not change this (unless you are changing compiler configuration).

The NEMO_SRC is the path to the nemo source code directory. These are any changes that will be copied to MY_SRC during the nemo compilation. You can change this if you want to recompile with a different source code. Make sure whichever source code you use is compatible with the NEMO revision you are using.

Select model versions

Many different version and revisions of XIOS, NEMO, WW3 and OASIS exist. In the next part of the code you can select which ones you want to compile with. By default, this setup uses XIOS v2.5 rev1964 and NEMO v4.0.4 rev13653, which are also used in AMM15_CO9_p2.
Note: most of the Met Office work on AMM15 starts from NEMO v4.0.4 rev.14075, and source code modified from it.

For the WW3 model, the code is downloaded directly from the Met Office development repository (not via svn); this is WW3 v7.14. Instead of a revision the WW3_REV indicates a specific commit of the git branch that you want to work with. The commit used here is not the most recent on.
Note: to see existing commits of the ww3 git branch (after it's been checked out) you can cd into the git directory and use git log . If you don't want to checkout a specific commit, but just can comment out git checkout $WW3_REV in the Compile WW3 section around line 284 in the script.

For OASIS we are checking the libraries out of a repository too. This automatically downloads the latest revision (for this work, we have used OASIS3-MCT_5.0 and OASIS3-MCT_6.0).
Note: this should be improved; I think the Met Office uses OASIS3-MCT_4.0.
Note: to check which oasis version you are using, you can check in the README.md file that downloads in the oasis3-mct directory once you check out oasis.

#################################################################################################
# select models and components - user can amend
#################################################################################################
# XIOS version and revision
XIOS_VER=2.5 
XIOS_REV=1964

# NEMO model, version and revsion to be checked out via svn 
NEMO_VER=4.0.4
NEMO_REV=13653

#WW3 GIT repository and commit
#NOTE; this GIT is the Met Office development version 7.14.
#It is updated often; with WW3_REV you are selecting a specific git commit to checkout.
#This is not the latest version. Use 'git log' to see all commits from the WW3 git repository once it's checked out.   
WW3_GIT=https://github.com/NOAA-EMC/WW3.git
WW3_REV=d3ea810da35e9266a4163b4b8f2f4cba5599a5eb

# OASIS GIT repository
# NOTE; no OASIS_REV set. Will use the latest version. 
# On 30/01/25; using commit 5e524d1ffcdb6d4177a879fada4a2639d89e3661 (HEAD -> master, origin/master, origin/HEAD)
# the README.txt in the oasis git repository contains more info on the version downloaded.
OASIS_GIT=https://gitlab.com/cerfacs/oasis3-mct.git

Load correct modules.

From this section onwards, you're better off not changing anything unless you are doing development or know what you're doing.

A first section of the code just checks that all paths are in place and load the correct module for the compiler configuration that you are using. The modules loaded for this configuration are in the co9_modules_gnu-mpich file.
Note: if you wanted to use a different compiler (eg. Cray), you will need to change this module list accordingly. When you do that, rename your HPC_TARG to a new configuration name, and change line 87 (currently archer2-gnu-r8-d8) . $REPO_DIR/ARCHER2/modules/co9_modules_gnu-mpich```` ) so thatarcher2-gnu-r8-d8``` is your new HPC_TARG name. This way it will be recognised. The point is to keep track of which module you load with a specific compiler configuration so there is less chaos in the end. You can find example of this in the archer helpdesk repository here.

The end of this section also loads some libraries that will be needed mainly for the WW3 compilation.

You will also be mode into the WORK_DIR directory to start the compilations.

#################################################################################################
# user, don't touch below...behave!
#################################################################################################

#Check path are loaded correctly
echo $WORK_DIR

if [ ${WORK_DIR:0:1} != "/" ]; then
  echo "WORK_DIR must use full path"
  exit 1
fi

if [ ${XIOS_DIR:0:1} != "/" ]; then
  echo "XIOS_DIR must use full path"
  exit 1
fi

if [ ${REPO_DIR:0:1} != "/" ]; then
  echo "REPO_DIR must use full path"
  exit 1
fi

# Generate work dire if doesn't exist already.
if [ ! -d "$WORK_DIR" ]; then
  mkdir $WORK_DIR
fi

# Move into work directory.
cd $WORK_DIR

# Check that all correct module are loaded.
echo "Making sure that the correct modules are loaded"

case "${HPC_TARG}"
  in
  archer2-gnu-r8-d8) . $REPO_DIR/ARCHER2/modules/co9_modules_gnu-mpich
           ;;
  *)       echo "Machine not recognised"
           echo "Machines available: archer2-gnu-mpich"
           exit 1
esac

# export librbary
export LD_LIBRARY_PATH=$CRAY_LD_LIBRARY_PATH:$LD_LIBRARY_PATH
export WWATCH3_NETCDF=NC4
export NETCDF_CONFIG=$(which nc-config)

Compile OASIS

Important: Before downloading OASIS3-MCT you should fill this registration form to comply with OASIS usage policy.

The first step in setting up the coupled system is to download and compile the required libraries, including XIOS if used. Unlike the compilation of NEMO or WW3, which produces an executable, compiling OASIS3-MCT does not generate a standalone binary. Instead, the process builds the necessary libraries, which are then linked to the component models during their compilation. This ensures that the coupling interface functions correctly within the coupled system.
Note: you can find the oasis3-mct user guide here.
Courses, training and more information on the oasis system are available on their website here.
Copyright information are available here.

The code will first check if you already have the oasis3-mct library directory there (i.e. if you already downloaded oasis). I you do not, it will clone the oasis repository from the oasis3-mct gitlab.

################################################################################################
# Install OASIS3-MCT
###############################################################################################
#export ROOT_DIR=$WORK_DIR

if [ ! -d ./oasis3-mct ]; then
  git clone $OASIS_GIT
fi

For the compilation to function, oasis need an HPC specific file called make.your_platform (see section 6.1 of the oasis userguide ).

For Archer2 in this specific architecture configuration you will use the make.archer2-gnu-r8-d8.
Note: you will need to amend this if you change compiler options.

The code copies the pre-made file to the oasis make_dir directory, which you should now have after cloning the oasis gitlab.

#set up directory structure
arch_file=${WORK_DIR}/oasis3-mct/util/make_dir/make.${HPC_TARG}

#copy oasis make.file 
cp $REPO_DIR/ARCHER2/arch/oasis/make.${HPC_TARG} ${arch_file}

You then need to update the paths in the make.archer2-gnu-r8-d8 to match the location of your oasis directory, and where you want the libraries to compile. The code automatically does this, as below:

#update the make.file with current path to oasis main directory, 
#and with the name of an installation directory (this gets created when compiling)
sed -i 's#COUPLETEMPLATE#'"${WORK_DIR}/oasis3-mct"'#' ${arch_file}
sed -i 's#ARCHTEMPLATE#'"${WORK_DIR}/install/oasis3-mct/${HPC_TARG}"'#' ${arch_file}

You should also amend the path of the make.inc file accordingly. This file is also needed to compile the oasis liraries.
Again, the code does this automatically as below:

# update the path in make.inc (should download with oasis git)
make_inc=${WORK_DIR}/oasis3-mct/util/make_dir/make.inc
sed -i 's#include .*#'"include ${arch_file}"'#' ${make_inc}

Finally, you should move into the /oasis3-mct/util/make_dir directory to compile oasis.
The make realclean -f TopMakefileOasis3 is used to make sure any previous compilation is cleared.
The make -f TopMakefileOasis3 is the compilation command.

###############
# Compile OASIS

cd ${WORK_DIR}/oasis3-mct/util/make_dir
#remove previous compilations
make realclean -f TopMakefileOasis3
#compile
make -f TopMakefileOasis3

Finally, we keep a copy of the error and log files in case something goes wrong during the compilation.

# Make a copy of the log files
cp COMP.log make.${HPC_TARG}.log
cp COMP.err make.${HPC_TARG}.err

Compile XIOS

The next section of the script downloads and compiles the XIOS.
Note (!) : The order in which you compile the programs matters. XIOS needs to be compiled before NEMO, which needs to be compiled before WW3.

The first part of this section checks if the $WORK_DIR that you have defined in the set path section is there. If not, it will create it based the the $CONFIG name you chose.

#################################################################################################
#   XIOS installation
#################################################################################################
cd $WORK_DIR

echo $WORK_DIR
# Choose an appropriate directory for your XIOS installation
if [ ! -d "$WORK_DIR" ]; then
  mkdir $WORK_DIR
fi

Then you move into the $WORK_DIR and checkout the XIOS code from the official repository into the xios directory.

cd $WORK_DIR

echo $PWD
echo "Checking out xios repository"
svn co http://forge.ipsl.fr/ioserver/svn/XIOS/branchs/xios-$XIOS_VER@$XIOS_REV $XIOS_DIR

After moving into the xios directory, the architecture files for Archer2 (with Gnu compiler) are copied from this repository into the xios's arch directory (this is generated when you checkout xios).

cd xios
cp $REPO_DIR/ARCHER2/arch/xios/arch-${HPC_TARG}.fcm ./arch/arch-${HPC_TARG}.fcm #copy arch files for coupled config
cp $REPO_DIR/ARCHER2/arch/xios/arch-generic.path ./arch/arch-${HPC_TARG}.path #copy arch and upadte name
cp $REPO_DIR/ARCHER2/arch/xios/arch-generic.env ./arch/arch-${HPC_TARG}.env #copy arch and update name

Now you need to update the OASIS path in the XIOS's architecture file called arch-generic.path. In the file, the placeholder OASISTEMPLATE gets replaced with your personal oasis directory path.
Note: The arch-generic.path must include the following variables for the coupling to work:

  • OASIS_INCDIR="-I ${OASIS_DIR}/include"
  • OASIS_LIBDIR="-L ${OASIS_DIR}/lib"
  • OASIS_LIB="-lpsmile.MPI1 -lscrip -lmct -lmpeu"

These are already included in this arch-generic.path, but if you are starting from a different configuration file, you may need to add them manually.

# Update the oasis location template in the path file
sed -i 's#OASISTEMPLATE#'"${WORK_DIR}/install/oasis3-mct/${HPC_TARG}"'#' \
    $WORK_DIR/xios/arch/arch-${HPC_TARG}.path

Then, in the make_xios the flag use_oasis is switched to true.

echo "Compiling xios"

# Change the make_xios, use_oasis to true
sed -i 's|^use_oasis="false"$|use_oasis="true"|' ./make_xios

Finally, the script compiles the xios executable with ./make_xios.
Note: This uses the flags --use_oasis oasis3_mct

#compile
#./make_xios --full --prod --arch ${HPC_TARG} --netcdf_lib netcdf4_par --job 4
./make_xios --full --prod --use_oasis oasis3_mct --arch ${HPC_TARG} --netcdf_lib netcdf4_par --job 4

Compile NEMO

This section downloads and compiles NEMO.

First, the NEMO is checked out into the nemo directory via svn.
Then, the code moves into the nemo directory and checks that some important files are in place.

Note: here we are only downloading parts of the nemo files to save space. If you want everything, instead of these three svn co commands you can use:
svn co -r$NEMO_REV http://forge.ipsl.fr/nemo/svn/NEMO/releases/r4.0/r$NEMO_VER nemo

#################################################################################################
# Checkout the NEMO code from the SVN Paris repository 
#################################################################################################
cd $WORK_DIR
echo "Checking out NEMO repository"

svn co -r$NEMO_REV http://forge.ipsl.fr/nemo/svn/NEMO/releases/r4.0/r$NEMO_VER --depth empty nemo
svn co -r$NEMO_REV http://forge.ipsl.fr/nemo/svn/NEMO/releases/r4.0/r$NEMO_VER/src --depth infinity nemo/src
svn co -r$NEMO_REV http://forge.ipsl.fr/nemo/svn/NEMO/releases/r4.0/r$NEMO_VER/cfgs/SHARED nemo/cfgs/SHARED
svn export http://forge.ipsl.fr/nemo/svn/NEMO/releases/r4.0/r$NEMO_VER/cfgs/ref_cfgs.txt nemo/cfgs/ref_cfgs.txt

cd nemo

# Now check EXTERNALS revision number before checking out the rest
for ext_name in mk FCM IOIPSL   
  do   
  ext=`svn propget svn:externals | grep $ext_name | cut -c2-`   
  svn co http://forge.ipsl.fr/nemo/svn/$ext
done

ext=`svn propget svn:externals | grep makenemo | cut -c2-`
svn export http://forge.ipsl.fr/nemo/svn/$ext
#################################################################################################

Then, a few directories are set-up. The directory arch is created within nemo; it will later contain the architecture files for the compilation. The $WORK_DIR/nemo/cfgs/AMM15 is also created here; it will be where the model is compiled.

mkdir arch

# Setup the directory structure
mkdir $WORK_DIR/nemo/cfgs/AMM15

Making sure we are in the nemo directory, we copy the architecture files from this repository into the arch directory.
Note: they are set for Gnu, if you change compiler you will need to change these.

#################################################################################################
# Compile NEMO:
#################################################################################################
#copy the template arch file
cd $WORK_DIR/nemo
cp $REPO_DIR/ARCHER2/arch/nemo/* ./arch

The paths to XIOS and OASIS need to be amended in the NEMO arch-archer2-gnu-r8-d8.fcm.
Note: The nemo arch*fcm file must include the following variable for the coupling to work:

  • %OASIS_INC -I%OASIS_HOME/build/lib/mct -I%OASIS_HOME/build/lib/psmile.MPI1
  • %OASIS_LIB -L%OASIS_HOME/lib -lpsmile.MPI1 -lmct -lmpeu -lscrip
  • %USER_INC %XIOS_INC %OASIS_INC %NCDF_INC
  • %USER_LIB %XIOS_LIB %OASIS_LIB %NCDF_LIB
    These are already included in arch-archer2-gnu-r8-d8.fcm, if you start from a different file make sure to add them.
# Udate Xios and Oasis direcotries in the nemo arch file
#install=${ROOT_DIR}/install
#NOTE:in the arch file the following flags should be active for the coupling.
#%USER_INC            %XIOS_INC %OASIS_INC %NCDF_INC
#%USER_LIB            %XIOS_LIB %OASIS_LIB %NCDF_LIB
sed -i 's#OASISTEMPLATE#'"$WORK_DIR/install/oasis3-mct/${HPC_TARG}"'#' ./arch/arch-${HPC_TARG}.fcm
sed -i 's#XIOSTEMPLATE#'"$WORK_DIR/xios"'#'        ./arch/arch-${HPC_TARG}.fcm
echo 'AMM15 OCE' >> $WORK_DIR/nemo/cfgs/work_cfgs.txt
echo "Gathering forcing data"

Then, the code exports the $CONFIG_DIR and moves into the nemo directory to prepare for compilation.

#set path - update config dir
export CONFIG_DIR=$WORK_DIR/nemo/cfgs/AMM15
echo $CONFIG_DIR

# move in nemo dir and copy the amm15 source code
cd $WORK_DIR/nemo
mkdir -p $CONFIG_DIR/MY_SRC

The source code containing any changes to the original nemo code is copied at this stage. If you compiled NEMO before, this is the code you are likely used to see it in the MY_SRC directory. The script is using whatever code you are linking to in the $NEMO_SRC, which was defined at the start in the set-paths section. In this case, we are using AMM15_C09_p2, with changes added to include the Met Office 360 calendar system and improvement to the seabed stress diagnostic in dynzdf.f90.
Note: you can change the source code you use, just make sure it is compatible with the version and revision of NEMO you are using.

#Cope src for AMM15_cO9_p2 with modified dynzdf.f90 and corrected bdytides.F90 
cp $NEMO_SRC/* $CONFIG_DIR/MY_SRC/ #regular 360 days calendar

The cpp*.fcm file needed by NEMO is also copied.
Note: this needs to contain the flag key_oasis3 for the coupling to work.
The cpp_AMM15coupled.fcm already contains it.

#copy cpp*.fcm. 
#Note: must contain oasis key.cpp_AMM15coupled.fcm already contains it. 
#if starting from a file made for ocean-only you can add the key with: 
#sed -i 's/$/ key_oasis3/' $CONFIG_DIR/cpp_AMM15.fcm 
cp $REPO_DIR/AMM15/fcm/cpp_AMM15coupled.fcm $CONFIG_DIR/cpp_AMM15.fcm

Finally the script compiles NEMO, after making sure that any previous compilation is cleaned out.

#clean previous compiletions
#echo " clean previous nemo compilation"
./makenemo -m ${HPC_TARG} -r AMM15 -j 16 clean

#compile
echo "Compiling nemo AMM15 Config"
./makenemo -m ${HPC_TARG} -r AMM15 -j 16

The following few line are not necessary for the comilation but are part of the script.
Here the run directory starts being set up in $CONFIG_DIR/EXPREF/, so that you don't have to copy all executable manually later. This also copies the setup_test_coupled_360cal.sh script that you can use later to set-up a test run. The iodef.xml file is changed to turn on the using_oasis option within the file.

#################################################################################################
# Start setting up run directory
cd $CONFIG_DIR
mkdir $CONFIG_DIR/EXPREF
cp -r $REPO_DIR/EXPREF/setup_test_coupled_360cal.sh $CONFIG_DIR/EXPREF/
cp $XIOS_DIR/bin/xios_server.exe $CONFIG_DIR/EXPREF/xios_server.exe
cp $CONFIG_DIR/BLD/bin/nemo.exe  $CONFIG_DIR/EXPREF/nemo.exe
cp $REPO_DIR/EXPREF/files_test_coupled_360cal/*xml $CONFIG_DIR/EXPREF/.

# turn on oasis flag in iodef.xml 
# NOTE:do not remove the apparently useless spaces in the line below. I know they're annoying, but they need to be there.  
sed -i 's|<variable id="using_oasis"               type="bool">false</variable>|<variable id="using_oasis"               type="bool">true</variable>|' $CONFIG_DIR/EXPREF/iodef.xml

Compile WW3

The last model to compile is WW3.

The code moves back in the $WORK_DIR, exports the OASISDIR pointing to where you compiled oasis3-mct, then checks if the ww3 exists. If not, it is created when the WW3 git repository is cloned with git clone $WW3_GIT ww3.
After cloning and moving into the ww3 diectory, a specific commit of the repository is checked out with git checkout $WW3_REV. This is useful as the Met Office develops this repository quite often, and it's good to keep track of exactly what version of it you are working with.
Then, using sh model/bin/ww3_from_ftp.sh we expand some heavy files contained in the repository. As of today (04/02/25) they seem to be only example files.

###################################################################################################
# Compile WW3:
###################################################################################################
cd $WORK_DIR

#load netcdf libraries
echo $NETCDF_DIR /opt/cray/pe/netcdf/4.9.0.1/crayclang/14.0/

# export the oasis directory for compile
export OASISDIR=${WORK_DIR}/install/oasis3-mct/${HPC_TARG}

# download ww3 repo and expand large files
if [ ! -d ./ww3 ]; then
  git clone $WW3_GIT ww3
  cd ww3
  git checkout $WW3_REV
  sh model/bin/ww3_from_ftp.sh
fi

The files essential for the WW3 compilation are copied from thsi repository. These are the ad3.Gnu, comp.Gnu and link.Gnu, as well as two switch* files, one for parallel and one for serial compilation (see here).
The flags COU OASIS OASOCM need to be included in these switch* files for the coupled compilation to work. Also, you want to change any CRT* option within the file to CRT0 (see documentation for WW3 v.5.16. This is a WW3 previous version that what we use, but has some useful information anyway) )

# Copy comp, link, ad3 and switch files to your ww3/model/bin directory
# they are set for compile on archer2 with gnu
cp $REPO_DIR/WW3/*Gnu $WORK_DIR/ww3/model/bin
cp $REPO_DIR/WW3/switch* $WORK_DIR/ww3/model/bin

# add oasis flags to switch file and chang to CRT0 option
sed -i 's/$/ COU OASIS OASOCM/' $WORK_DIR/ww3/model/bin/switch_ECOWNDserial
sed -i 's/CRT1/CRT0/g' $WORK_DIR/ww3/model/bin/switch_ECOWNDserial

sed -i 's/$/ COU OASIS OASOCM/' $WORK_DIR/ww3/model/bin/switch_ECOWNDparal
sed -i 's/CRT1/CRT0/g' $WORK_DIR/ww3/model/bin/switch_ECOWNDparal

The *.Gnu files (in particular comp.Gnu) are essentially the equivalent of NEMO's architecture files, and contain all specific options. However, they are structured differently than the NEMO file. To make sure you are compiling consistently with NEMO, export FC and FFLAGS consistent with what you have used for the NEMO compilation in arch-archer2-gnu-r8-d8.fcm.
Note: yes, the FC=gfortran below is consistent with the %FC ftn -g in the NEMO arch file. This was checked.
Note: I am unfamiliar with the WW3 files, so if you notice anything odd, please let me know.

####################################################################
#Set Fortran compiler Flags
####################################################################
#IMPORTANT to be consistent with your NEMO compile
#check FFLAGS in your nemo arch file
#the -fdefault-real-8 -fdefault-double-8 -O1 should be there too
export FC=gfortran
export FFLAGS="-g -fdefault-real-8 -fdefault-double-8 -O1"

The code then moved into the ww3 directory and runs a comand to setup the environment structure before compiling. This is done once without any options, just to setup the directories.
You will be prompted for Update settings ? [y/n], you should answer n.

####################################################################
# setup environment structure
####################################################################
#Run without compilation option to setup the environment directories
cd $WORK_DIR/ww3
./model/bin/w3_setup model

Then we run the same command again pointing to the *.Gnu and switch* files.
This will be done twice, the first time we are setting up the environment to compile in parallel using the switch_ECOWNDparal.
You will be prompted for Update settings ? [y/n], you should answer n.

Then, we move into the $WORK_DIR/ww3/model/bin/ to compile using the command: ./w3_make ww3_shel ww3_multi
Note: the WW3 executable ww3_shel and ww3_multi must be compiled in parallel.

####################################################################
# setup environment for parallel compile
####################################################################
#Run the model environment setup comand with -s <switch> and -c  <comp> options before compiling.
#note: the switch_MYSWITCH was called switch_NEW before renaming.
cd $WORK_DIR/ww3
./model/bin/w3_setup model -c Gnu -s ECOWNDparal
# TODO:  Can you automate the reply to the prompt??
# add later

#######################
# COMPILE WW3 parallel
#######################
cd  $WORK_DIR/ww3/model/bin/
./w3_make ww3_shel ww3_multi
#the exectuables should now be in $WORK_DIR/ww3/model/exe/

We then do the same again, but using the switch_ECOWNDserial for serial compilation. You will be prompted for Update settings ? [y/n], you should answer n.
Note: the WW3 executables ww3_grid, ww3_strt, ww3_outf, ww3_outp, ww3_trck, ww3_grib, gx_outf, gx_outp, ww3_bounc, ww3_ounf, ww3_ounp, ww3_prep, ww3_prnc must be compiled in serial.

####################################################################
# setup environment for serial compile
####################################################################
#Run the model environemnt setup comand with -s <switch> and -c  <comp> options before compiling.
#note: the switch_MYSWITCH was called switch_NEW before renaming.
cd $WORK_DIR/ww3
./model/bin/w3_setup model -c Gnu -s ECOWNDserial
# TODO:  Can you automate the reply to the prompt??
# add later

#######################
# COMPILE WW3 serial
#######################
cd  $WORK_DIR/ww3/model/bin/
./w3_make ww3_grid ww3_strt ww3_outf ww3_outp ww3_trck ww3_grib gx_outf gx_outp ww3_bounc ww3_ounf ww3_ounp ww3_prep ww3_prnc
#the exectuables should now be in $WORK_DIR/ww3/model/exe/

I had issues with the first compilation overwriting the second one, so the following part of the code checks for the executable from the first (parallel) compilation after the second one (serial) is done. If it does not find it, we are recompiling again (in parallel) for ww3_shel and ww3_multi.
Note: This is quite odd and I've not worked out why it happens, but recompiling seems to fix it. It does not seem to make a difference which order I compile in (if serial or parallel first). If you can work out why the first compilation overwrite the second one, but the third one is fine, please let me know.

####################################################################
#Check that the excutable are there
#had issues with the exe from the first compilation being overwritten
#by the second compilation. If that happens compile again.

if [ ! -d $WORK_DIR/ww3/model/bin/ww3_shel ]; then
        cd $WORK_DIR/ww3
        ./model/bin/w3_setup model -c Gnu -s ECOWNDparal
        cd  $WORK_DIR/ww3/model/bin/
        ./w3_make ww3_shel ww3_multi
fi

Finally, we copy the wave model executables into the run directory. As they are many, this copies the full exe directory rather than having all the executables scattered around the run directory ( this will be $WORK_DIR/nemo/cfgs/AMM15/EXPREF).

#####################################################################
#  add to run directory setup
#####################################################################
# cp executables in the EXPREF dir that you after compiling nemo
export CONFIG_DIR=$WORK_DIR/nemo/cfgs/AMM15

#link executable
if [ ! -d $WORK_DIR/nemo/cfgs/AMM15/EXPREF/exe ]; then
        ln -s $WORK_DIR/ww3/model/exe/ $WORK_DIR/nemo/cfgs/AMM15/EXPREF
fi

Now if you move into $WORK_DIR/nemo/cfgs/AMM15/EXPREF, you should have a directory containing all you executables and a script to setup a test run.

Clone this wiki locally