CROCO-WW3
---------

In your ${CHOME} repository you should have already filled in ``myenv_mypath.sh``.

To prepare the run you need to modify the files ``myjob.sh`` and ``mynamelist.sh``.

* In ``myjob.sh`` , you will have to fill in information about dates, job sequence:
  ::

      # Real job duration in sec (converted to MACHINE format in submit job)
      export TIMEJOB=1800

      #-------------------------------------------------------------------------------
      # Run date settings
      #-------------------------------------------------------------------------------
      # Your run can be divided into several jobs (e.g.: 1 year run into 12 jobs of 1 month)

      # Start date of the first Job
      export YEAR_BEGIN_JOB=2005
      export MONTH_BEGIN_JOB=1
      export DAY_BEGIN_JOB=1

      # Duration of each Job
      export JOB_DUR_MTH=1
      export JOB_DUR_DAY=0

      # How many jobs do you want to launch?
      export NBJOB=1           

      # Do we start from a restart?
      export RESTART_FLAG="FALSE"

  Along with the number of cpu you will use for each model
  ::
    
      # nb of CPUs for each model
      export NP_OCEX=2
      export NP_OCEY=2
      export NP_WAV=14

* In ``mynamelist.sh``, first specify the run type, and the name of the experiment:
  ::

      # Run type (o/a/w, w.Afrc, oa, 2o1a, owa, owa.full...)
      #  - Will select the models to use reading letters o/w/a/toywav/toyoce/toyatm 
      #  - Will select the executables, and some options (see in the following sections)
      #  - In coupled mode corresponds to the suffix of the OASIS_IN/namcouple.base.$RUNtype to use
      export RUNtype=ow
      export MOD=`echo $RUNtype | cut -d . -f 1`
       
      #  Name of the experiment you are about to launch (max 30. CHAR)
      export CEXPER=BENGUELA_example_${RUNtype}

  Then, there is a section indicating where the run will be executed and where 
  the outputs and restarts will be stored:
  ::

      #-------------------------------------------------------------------------------
      # RUN_DIR
      #-------------------------------------------------------------------------------
      
      export EXEDIR_ROOT="$CWORK/rundir/${CEXPER}_execute"
      export OUTPUTDIR_ROOT="$CWORK/rundir/${CEXPER}_outputs"
      export RESTDIR_ROOT="$CWORK/rundir/${CEXPER}_restarts"
      
      export  JOBDIR_ROOT=${CHOME}/jobs_${CEXPER}

  Then, there are sections for the different components.

  For the coupler settings:
  ::

      #-------------------------------------------------------------------------------
      # CPL
      #-------------------------------------------------------------------------------
      
      # Namelist
      #---------
      # Note: namelist example files are provided in OASIS_IN/
      # if you want to use a pre-built weight file for grid interpolations, point to 
      # e.g. namcouple.base.oa.smtho2a 
      export namcouplename=namcouple.base.${RUNtype}
      
      # Coupling frequency
      #-------------------
      export CPL_FREQ=21600
      
      # Restart files for OASIS
      #------------------------
      # If TRUE: create OASIS restart files from pre-existing atm/oce/wav outputs.
      # If FALSE: create OASIS restart files from calm conditions (need to read at least the grid for each model)
      export CPL_restart="FALSE"
      export oce_rst_file="${OCE_FILES_DIR}/croco_grd.nc"
      export oce_rst_timeind=-1 # time index (-1 is last) in the file to extract as restart
      export atm_rst_file="${ATM_FILES_DIR}/wrfinput_dXX_2005_01_01_00" # the domain dXX will be automatically replaced
      export atm_rst_timeind=-1 # time index (-1 is last) in the file to extract as restart
      export wav_rst_file="${WAV_FILES_DIR}/ww3.200501.nc"
      export wav_rst_timeind=-1 # time index (-1 is last) in the file to extract as restart
      
  You should check the coupling frequency, the restart flag and path towards 
  model files to use to create oasis restart files.

  For CROCO settings, first indicate if you request CROCO compilation:
  ::

      #-------------------------------------------------------------------------------
      # OCE
      #-------------------------------------------------------------------------------

      # Where to find or put the croco execuatble
      export OCE_EXE_DIR=${CHOME}/CROCO_IN
      
      # Online Compilation
      #-------------------
      #!!!!!!! IMPORTANT NOTE !!!!!!!
      # If activated, creates croco executable depending on this namelist. 
      #   - In param.h it modifies the grid size, the number of procs in x and y direction with those given in myjob.sh
      #   - In cppdefs.h it modifies the following options with informations given below
      #       MPI, OA_COUPLING, OW_COUPLING, MRL_WCI, 
      #       XIOS, LOGFILE, MPI_NOLAND,
      #       AGRIF, AGRIF_2WAY, 
      #       BULK_FLUX, ONLINE, AROME, ARPEGE, ERA_ECMWF
      #       FRC_BRY, CLIMATOLOGY
      #       TIDES, PSOURCE, PSOURCE_NCFILE, PSOURCE_NCFILE_TS
      # Other changes of parameterizations, numerical schemes, etc should be made "by hand" in CROCO_IN/cppdefs.h.base
      #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      export ONLINE_COMP=1

  Then, edit model time steps:
  ::

      # Time steps
      #-----------
      export DT_OCE=3600
      export NDTFAST=60

  Then several options for zooms, wave coupling are provided.
  They are generally automatically set-up depending on the ``RUNtype`` defined 
  at the beginning.

  Then, edit the options regarding the forcing files:
  ::

      # Forcings
      #---------
      export ini_ext='ini_SODA' # ini extension file (ini_SODA,...)
      export bdy_ext='bry_SODA' # bry extension file (clm_SODA,bry_SODA,...)
      
      # flag for surface forcing should be true except in the case of atm coupling
      if [[ $MOD =~ .*a.* ]] ; then
          export surfrc_flag="FALSE"
      else
          export surfrc_flag="TRUE"
      fi
      export interponline=0 # switch (1=on, 0=off) for online surface interpolation. Only works with MONTHLY input files!
      export frc_ext='blk_ERA5' # surface forcing extension(blk_ERA5, frc_ERA5,...). If interponline=1 precise the type (ERA_ECMWF or AROME,  [CFSR by default], names as cppkey name in croco)
      
      export tide_flag="FALSE" # the forcing extension must be blk_??? otherwise tide forcing overwrites it 
      export river_flag="FALSE"

  Finally edit CROCO output settings:
  ::

      # Output settings
      #----------------
      #!!! WARNING: when XIOS is activated the following values (for the model) are not taken into account
      export oce_his_sec=86400     # history output interval (in number of second) 
      export oce_avg_sec=86400     # average output interval (in number of second) 

  Then go to the WAVE model section:
  ::

      #-------------------------------------------------------------------------------
      # WAV
      #-------------------------------------------------------------------------------
      
      # Where to find the wav executable
      if [[ $RUNtype =~ .*owa.* ]] ; then
          export WAV_EXE_DIR=${WAV}/exe_owa
      elif [[ $RUNtype =~ .*ow.* ]] ; then
          export WAV_EXE_DIR=${WAV}/exe_ow
      elif [[ $RUNtype =~ .*aw.* ]] ; then
          export WAV_EXE_DIR=${WAV}/exe_aw
      else
          export WAV_EXE_DIR=${WAV}/exe_frc
      fi
      
      # Namelist
      #---------
      # Chosing the ww3_shel.inp.base.SHELL_EXT (see options in WW3_IN)
      if [[ $RUNtype =~ .*toy.* ]] ; then
          export SHELL_EXT=$MOD
      else
          export SHELL_EXT=$RUNtype
      fi

  First the paths for the executable are defined, and the ww3_shel namelist to use is defined. 
  Those are generally set-up with the ``RUNtupe`` but can be changed if necessary. 

  Then edit the ww3 time steps and grid settings (these will be updated in ww3_grid.inp):
  ::
      
      # Time steps
      #-----------
      export DT_WAV=3600     # TMAX = 3*TCFL
      export DT_WW_PRO=1200  # TCFL = 0.8 x dx/(g/fmin4pi) with fmin=0.0373 => 3-4 % of dx
      export DT_WW_REF=1800  # TMAX / 2
      export DT_WW_SRC=10    # TSRC = usually 10s  (could be between 5s and 60s)
      
      # Grid size
      #----------
      export wavnx=41 ; export wavny=42
      
      # Parameter
      #---------- 
      export hmin=75; # e.g. minimum water depth in CROCO (will be used to delimit coastline in WW3)
      
  Then, choose the forcing to use for ww3:
  ::

      # Forcing files
      #--------------
      # forcin: forcing file(s) PREFIX list (input file are supposed to be in the form: PREFIX_Y????M??.nc)
      # forcww3: name of ww3_prnc.inp extension, e.g current or wind/era5, see in WW3_IN directory
      if [[ $RUNtype =~ .*owa.* ]]; then
          export forcin=()
          export forcww3=()
      elif [[ $RUNtype =~ .*Afrc.* || $RUNtype =~ .*ow.* ]] ; then
          export forcin=(ERA5_wind)
          export forcww3=(wind.era5)
      elif [[ $RUNtype =~ .*Ofrc.* ]] ; then
          export forcin=(CROCO_current CROCO_level)
          export forcww3=(current level)
      elif [[ $RUNtype =~ .*frc.* ]] ; then
          export forcin=(ERA5_wind CROCO_current CROCO_level)
          export forcww3=(wind.era5 current level)
      fi
      
  As well as the boundary data (can be left empty):
  ::

      # Boundary files
      #---------------
      # prefix for boundary files (leave empty is none), there are supposed to be in WAV_FILES_DIR
      export bouncin=
  
  Finally, set output settings:
  ::
    
      # Output settings
      #----------------
      export wav_int=21600  # output interval (s)
      export wav_pnt=0  # point output interval. Put 0 if no point output
      export point_output_list=${WAV_FILES_DIR}/my_point_output_test.txt # file where to find list of point (format: lon lat name) to output spectrum
      export wav_trck=0     # track output interval. Put 0 if no track output  
      export flagout="TRUE" # Keep (TRUE) or not (FALSE) the ww3 output binary files (e.g. out_grd.ww3)

* Now that you have completed the necessary files, you are ready to run your 
  simulation. To do so, simply do
  ::

      ./submitjob.sh

