New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
all_functions.sh in trunk/NEMOGCM/SETTE – NEMO

source: trunk/NEMOGCM/SETTE/all_functions.sh @ 2675

Last change on this file since 2675 was 2675, checked in by flavoni, 13 years ago

commit sette.sh ready to test 3 reference configuration: GYRE_LOBSTER, ORCA2_LIM_PISCES, POMME. (restartability and reproductibility tests), see ticket #752

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1######################################################
2# Author : Simona Flavoni for NEMO
3# Contact : sflod@locean-ipsl.upmc.fr
4#
5# ----------------------------------------------------------------------
6# NEMO/SETTE , NEMO Consortium (2010)
7# Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
8# ----------------------------------------------------------------------
9#
10# Some scripts called by sette.sh
11# all_functions.sh   : all functions used by sette.sh 
12######################################################
13#set -x
14set -o posix
15#set -u
16#set -e
17#+
18#
19# ================
20# all_functions.sh
21# ================
22#
23# ----------------------------------------------
24# Set of functions used by sette.sh (NEMO tests)
25# ----------------------------------------------
26#
27# SYNOPSIS
28# ========
29#
30# ::
31#
32#  $ ./set_namelist.sh INPUT_NAMELIST VARIABLE VALUE
33#
34#
35# DESCRIPTION
36# ===========
37#
38# function superegrep
39#   input variable value
40#
41# function set_namelist
42#   input namelist_name variable value
43#   output namelist
44#
45# EXAMPLES
46# ========
47#
48# ::
49#
50#  $ ./set_namelist.sh namelist          nn_itend        75
51#  $ ./set_namelist.sh namelist_ice_lim2 cn_icerst_in  \"00101231_restart_ice\"
52#
53#
54# TODO
55# ====
56#
57# option debug
58#
59#
60# EVOLUTIONS
61# ==========
62#
63# $Id$
64#
65#   * creation
66#-
67#
68
69
70# function to find namelists parameters
71supergrep () {
72            grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%"
73    }
74
75usage=" Usage : set_namelist input_namelist variable_name value"
76usage=" if value is a string ths is neede syntax : ./set_namelist namelist_name var_name \"new_value\" "
77
78# function to set namelists parameters
79set_namelist () {
80   minargcount=3
81   if [ ${#} -lt ${minargcount} ]
82   then
83      echo "not enought arguments for set_namelist"
84      echo "${usage}"
85      exit 1
86   fi
87   unset minargcount
88   if [  ! -f ${SETTE_DIR}/output.sette ] ; then
89                touch ${SETTE_DIR}/output.sette
90        fi
91
92        echo "executing script : set_namelist $@" >> ${SETTE_DIR}/output.sette
93        echo "################" >> ${SETTE_DIR}/output.sette
94     
95   VAR_NAME=$( supergrep $2 ${INPUT_DIR}/$1 )
96   if [ ${#VAR_NAME} -eq 0 ] 
97   then
98      echo "doing \"set_namelist $@\". "
99      echo "variable: \"$2\" is empty"
100      echo "control that variable $2 is in \"${INPUT_DIR}/$1\" "
101      echo "exit"
102      echo "error in executing script : set_namelist $@" >> ${SETTE_DIR}/output.sette
103      echo "....." >> ${SETTE_DIR}/output.sette
104      exit 1
105   fi
106        sed -e "s/${VAR_NAME}.*/${VAR_NAME}/" ${INPUT_DIR}/$1 > ${INPUT_DIR}/$1.tmp
107        mv ${INPUT_DIR}/$1.tmp ${INPUT_DIR}/$1
108        sed -e "s/${VAR_NAME}/$2=$3/"  ${INPUT_DIR}/$1 > ${INPUT_DIR}/$1.tmp
109        mv ${INPUT_DIR}/$1.tmp ${INPUT_DIR}/$1
110
111        echo "finished script : set_namelist $@" >> ${SETTE_DIR}/output.sette
112        echo "++++++++++++++++" >> ${SETTE_DIR}/output.sette
113        echo "                " >> ${SETTE_DIR}/output.sette
114}
Note: See TracBrowser for help on using the repository browser.