#!/bin/bash
#############################################################
# Author : Simona Flavoni for NEMO
# Contact : sflod@locean-ipsl.upmc.fr
#
# sette.sh   : principal script of SET TEsts for NEMO (SETTE)
# ----------------------------------------------------------------------
# NEMO/SETTE , NEMO Consortium (2010)
# Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
# ----------------------------------------------------------------------
#
#############################################################
#set -x
set -o posix
#set -u
#set -e
#+
#
# ================
# sette.sh
# ================
#
# ----------------------------------------------
# Set of tests for NEMO
# ----------------------------------------------
#
# SYNOPSIS
# ========
#
# ::
#
#  $ ./sette.sh
#
# DESCRIPTION
# ===========
#
# principal script is sette.sh, that calls 
#
#  makenemo 
#
#   creates the exectuable in ${CONFIG_NAME}/BLD/bin/nemo.exe 
#
#   (and its link opa in ${CONFIG_NAME}/EXP00)
#
#  param.cfg : sets and loads following directories
#
#   Executing directory (EXE_DIR)
#
#   Forcing files storing (FORCING_DIR)
#
#   Input files storing (INPUT_DIR)
#
#   Temporary directory (if needed) (TMPDIR)
# 
#   Validation directory (NEMO_VALIDATION_DIR)
#
#   (note: this file is the same for all configrations to be tested with sette)
#
#  all_functions.sh : loads functions used by sette (note: new functions can be added here)
#
#  set_namelist : function declared in all_functions that set namelist parameters for tests
#
#  fcm_job.sh 
#
#   runs job and saves output files (grid_files, restarts, ice_evolu, ftrace.out)
#
#   and it creates tree of VALIDATION, in which there are restart files, solver.stat and ocean.output
#
#   Tree of VALIDATION is:
#
#   NEMO_VALIDATION_DIR/WCONFIG_NAME/WCOMPILER_NAME/TEST_NAME/REVISION_NUMBER(or DATE)
# 
#   (note this job needs to have an input_CONFIG.cfg in which can be found input tar file)
#
#   (note other files can be saved adding at the end of fcm_job list of saved files)
# 
#  NOTE: if job is not launched for some problems you have executable ready in ${CONFIG_NAME}/EXP00 directory
#
#  NOTE: the changed namelists are leaved in ${CONFIG_NAME}/EXP00 directory
# 
#  in ${SETTE_DIR} is created output.sette with the echo of commands run
#
#  if sette.sh is stopped in output.sette there is written the last command executed by sette.sh
#
#  if you run: ./sette.sh 2>&1 | tee out.sette
#
#  in ${SETTE_DIR} out.sette is redirected standard error & standard output
#
#
# EXAMPLES
# ========
#
# ::
#
#  $ ./sette.sh 
#
#
# TODO
# ====
#
# option debug
#
# EVOLUTIONS
# ==========
#
# $Id$
#
#   * creation
#
#-
#
SETTE_DIR=/PATH/OF/SETTE

cd ${SETTE_DIR}
. ../CONFIG/makenemo -m ifort_linux -n GYRE_1_1 -r GYRE
cd ${SETTE_DIR}
. param.cfg
. all_functions.sh
set_namelist namelist nn_it000 1
set_namelist namelist nn_itend 75
cd ${SETTE_DIR}
. ./fcm_job.sh input_GYRE.cfg 1

cd ${SETTE_DIR}
. ../CONFIG/makenemo -n ORCA2_LIM_1_2 -r ORCA2_LIM add_key "key_mpp_mpi key_nproci=1 key_nprocj=2"
cd ${SETTE_DIR}
. param.cfg
. all_functions.sh
set_namelist namelist nn_it000 1
set_namelist namelist nn_itend 75
cd ${SETTE_DIR}
. ./fcm_job.sh input_ORCA2_LIM.cfg 2

