###################################################### # Author : Simona Flavoni for NEMO # Contact : sflod@locean-ipsl.upmc.fr # # ---------------------------------------------------------------------- # NEMO/SETTE , NEMO Consortium (2010) # Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) # ---------------------------------------------------------------------- # # Some scripts called by sette.sh # all_functions.sh : all functions used by sette.sh ###################################################### #set -x set -o posix #set -u #set -e #+ # # ================ # all_functions.sh # ================ # # ---------------------------------------------- # Set of functions used by sette.sh (NEMO tests) # ---------------------------------------------- # # SYNOPSIS # ======== # # :: # # $ ./set_namelist INPUT_NAMELIST VARIABLE VALUE # $ ./copy_original INPUT_NAMELIST # # # DESCRIPTION # =========== # # function superegrep # input variable value # # function copy_original # input namelist_name # output namelist # # function set_namelist # input namelist_name variable value # output namelist # # EXAMPLES # ======== # # :: # # $ ./copy_original namelist_pisces # $ ./set_namelist namelist nn_itend 75 # $ ./set_namelist namelist_ice_lim2 cn_icerst_in \"00101231_restart_ice\" # # # TODO # ==== # # option debug # # # EVOLUTIONS # ========== # # $Id$ # # * creation #- # # function to copy original namelists in ORIGINAL_namelist directory in ${INPUT_DIR} directory # to allow re-run same tests in same directory and start with all correct values of namelist copy_original () { `mkdir -p ${INPUT_DIR}/ORIGINAL_namelist` if [ -d ${INPUT_DIR}/ORIGINAL_namelist ] ; then echo "created ${INPUT_DIR}/ORIGINAL_namelist directory in ${INPUT_DIR}" >> ${SETTE_DIR}/output.sette else echo "problems in creating ${INPUT_DIR}/ORIGINAL_namelist directory" >> ${SETTE_DIR}/output.sette echo "EXIT," exit 1 fi `cp ${CONFIG_DIR}/${REF_CONF}/EXP00/$1 ${INPUT_DIR}/ORIGINAL_namelist/$1.ori` if [ -n "$(ls ${INPUT_DIR}/ORIGINAL_namelist/$1.ori)" ] ; then echo "copied namelist of reference configuration in ${INPUT_DIR}/ORIGINAL_namelist/$1.ori " >> ${SETTE_DIR}/output.sette else echo "problem in copying namelist of reference configuration in ${INPUT_DIR}/ORIGINAL_namelist/$1.ori " >> ${SETTE_DIR}/output.sette echo "EXIT," exit 1 fi `cp ${INPUT_DIR}/ORIGINAL_namelist/$1.ori ${INPUT_DIR}/$1` if [ -n "$(ls ${INPUT_DIR}/$1)" ] ; then echo "copied original namelist in ${INPUT_DIR} directory " >> ${SETTE_DIR}/output.sette else echo "problem in copying original namelist in ${INPUT_DIR} directory" >> ${SETTE_DIR}/output.sette echo "EXIT," exit 1 fi } # function to find namelists parameters supergrep () { grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%" } usage=" Usage : set_namelist input_namelist variable_name value" usage=" if value is a string ths is neede syntax : ./set_namelist namelist_name var_name \"new_value\" " # function to set namelists parameters set_namelist () { minargcount=3 if [ ${#} -lt ${minargcount} ] then echo "not enought arguments for set_namelist" echo "${usage}" exit 1 fi unset minargcount if [ ! -f ${SETTE_DIR}/output.sette ] ; then touch ${SETTE_DIR}/output.sette fi echo "executing script : set_namelist $@" >> ${SETTE_DIR}/output.sette echo "################" >> ${SETTE_DIR}/output.sette VAR_NAME=$( supergrep $2 ${INPUT_DIR}/$1 ) if [ ${#VAR_NAME} -eq 0 ] then echo "doing \"set_namelist $@\". " echo "variable: \"$2\" is empty" echo "control that variable $2 is in \"${INPUT_DIR}/$1\" " echo "exit" echo "error in executing script : set_namelist $@" >> ${SETTE_DIR}/output.sette echo "....." >> ${SETTE_DIR}/output.sette exit 1 fi sed -e "s/${VAR_NAME}.*/${VAR_NAME}/" ${INPUT_DIR}/$1 > ${INPUT_DIR}/$1.tmp mv ${INPUT_DIR}/$1.tmp ${INPUT_DIR}/$1 sed -e "s/${VAR_NAME}/$2=$3/" ${INPUT_DIR}/$1 > ${INPUT_DIR}/$1.tmp mv ${INPUT_DIR}/$1.tmp ${INPUT_DIR}/$1 echo "finished script : set_namelist $@" >> ${SETTE_DIR}/output.sette echo "++++++++++++++++" >> ${SETTE_DIR}/output.sette echo " " >> ${SETTE_DIR}/output.sette }