#!/bin/bash
######################################################
# Author : Simona Flavoni for NEMO
# Contact : sflod@locean-ipsl.upmc.fr
#
# 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.sh INPUT_NAMELIST VARIABLE VALUE 
#
#
# DESCRIPTION
# ===========
#
#
# Simple job for SET TESTS for NEMO (SETTE)

# function superegrep
# input variable value

# function set_namelist
# input namelist_name variable value
# output namelist

# 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 () {
     VAR_NAME=$( supergrep $1 ${INPUT_DIR}/namelist )
     sed -e "s/${VAR_NAME}/$1=$2/"  ${INPUT_DIR}/namelist > ${INPUT_DIR}/namelist.tmp
     mv ${INPUT_DIR}/namelist.tmp ${INPUT_DIR}/namelist
}
