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

Last change on this file since 2545 was 2545, checked in by flavoni, 10 years ago

improved READE and SETTE.pdf for SETTE, add small debug, see ticket #752

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