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 branches/nemo_v3_3_beta/NEMOGCM/SETTE – NEMO

source: branches/nemo_v3_3_beta/NEMOGCM/SETTE/all_functions.sh @ 2511

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

add control number of arguments for set_namelist function in SETTE, see ticket #752

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