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 |
---|
14 | set -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 INPUT_NAMELIST VARIABLE VALUE |
---|
33 | # $ ./copy_original INPUT_NAMELIST |
---|
34 | # |
---|
35 | # |
---|
36 | # DESCRIPTION |
---|
37 | # =========== |
---|
38 | # |
---|
39 | # function superegrep |
---|
40 | # input variable value |
---|
41 | # |
---|
42 | # function copy_original |
---|
43 | # input namelist_name |
---|
44 | # output namelist |
---|
45 | # |
---|
46 | # function set_namelist |
---|
47 | # input namelist_name variable value |
---|
48 | # output namelist |
---|
49 | # |
---|
50 | # EXAMPLES |
---|
51 | # ======== |
---|
52 | # |
---|
53 | # :: |
---|
54 | # |
---|
55 | # $ ./copy_original namelist_pisces |
---|
56 | # $ ./set_namelist namelist nn_itend 75 |
---|
57 | # $ ./set_namelist namelist_ice_lim2 cn_icerst_in \"00101231_restart_ice\" |
---|
58 | # |
---|
59 | # |
---|
60 | # TODO |
---|
61 | # ==== |
---|
62 | # |
---|
63 | # option debug |
---|
64 | # |
---|
65 | # |
---|
66 | # EVOLUTIONS |
---|
67 | # ========== |
---|
68 | # |
---|
69 | # $Id$ |
---|
70 | # |
---|
71 | # * creation |
---|
72 | #- |
---|
73 | # |
---|
74 | |
---|
75 | |
---|
76 | # function to copy original namelists in ORIGINAL_namelist directory in ${INPUT_DIR} directory |
---|
77 | # to allow re-run same tests in same directory and start with all correct values of namelist |
---|
78 | copy_original () { |
---|
79 | `mkdir -p ${INPUT_DIR}/ORIGINAL_namelist` |
---|
80 | if [ -d ${INPUT_DIR}/ORIGINAL_namelist ] ; then |
---|
81 | echo "created ${INPUT_DIR}/ORIGINAL_namelist directory in ${INPUT_DIR}" >> ${SETTE_DIR}/output.sette |
---|
82 | else |
---|
83 | echo "problems in creating ${INPUT_DIR}/ORIGINAL_namelist directory" >> ${SETTE_DIR}/output.sette |
---|
84 | echo "EXIT," |
---|
85 | exit 1 |
---|
86 | fi |
---|
87 | `cp ${CONFIG_DIR}/${REF_CONF}/EXP00/$1 ${INPUT_DIR}/ORIGINAL_namelist/$1.ori` |
---|
88 | if [ -n "$(ls ${INPUT_DIR}/ORIGINAL_namelist/$1.ori)" ] ; then |
---|
89 | echo "copied namelist of reference configuration in ${INPUT_DIR}/ORIGINAL_namelist/$1.ori " >> ${SETTE_DIR}/output.sette |
---|
90 | else |
---|
91 | echo "problem in copying namelist of reference configuration in ${INPUT_DIR}/ORIGINAL_namelist/$1.ori " >> ${SETTE_DIR}/output.sette |
---|
92 | echo "EXIT," |
---|
93 | exit 1 |
---|
94 | fi |
---|
95 | `cp ${INPUT_DIR}/ORIGINAL_namelist/$1.ori ${INPUT_DIR}/$1` |
---|
96 | if [ -n "$(ls ${INPUT_DIR}/$1)" ] ; then |
---|
97 | echo "copied original namelist in ${INPUT_DIR} directory " >> ${SETTE_DIR}/output.sette |
---|
98 | else |
---|
99 | echo "problem in copying original namelist in ${INPUT_DIR} directory" >> ${SETTE_DIR}/output.sette |
---|
100 | echo "EXIT," |
---|
101 | exit 1 |
---|
102 | fi |
---|
103 | } |
---|
104 | |
---|
105 | # function to find namelists parameters |
---|
106 | supergrep () { |
---|
107 | grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%" |
---|
108 | } |
---|
109 | |
---|
110 | usage=" Usage : set_namelist input_namelist variable_name value" |
---|
111 | usage=" if value is a string ths is neede syntax : ./set_namelist namelist_name var_name \"new_value\" " |
---|
112 | |
---|
113 | # function to set namelists parameters |
---|
114 | set_namelist () { |
---|
115 | minargcount=3 |
---|
116 | if [ ${#} -lt ${minargcount} ] |
---|
117 | then |
---|
118 | echo "not enought arguments for set_namelist" |
---|
119 | echo "${usage}" |
---|
120 | exit 1 |
---|
121 | fi |
---|
122 | unset minargcount |
---|
123 | if [ ! -f ${SETTE_DIR}/output.sette ] ; then |
---|
124 | touch ${SETTE_DIR}/output.sette |
---|
125 | fi |
---|
126 | |
---|
127 | echo "executing script : set_namelist $@" >> ${SETTE_DIR}/output.sette |
---|
128 | echo "################" >> ${SETTE_DIR}/output.sette |
---|
129 | |
---|
130 | VAR_NAME=$( supergrep $2 ${INPUT_DIR}/$1 ) |
---|
131 | if [ ${#VAR_NAME} -eq 0 ] |
---|
132 | then |
---|
133 | echo "doing \"set_namelist $@\". " |
---|
134 | echo "variable: \"$2\" is empty" |
---|
135 | echo "control that variable $2 is in \"${INPUT_DIR}/$1\" " |
---|
136 | echo "exit" |
---|
137 | echo "error in executing script : set_namelist $@" >> ${SETTE_DIR}/output.sette |
---|
138 | echo "....." >> ${SETTE_DIR}/output.sette |
---|
139 | exit 1 |
---|
140 | fi |
---|
141 | sed -e "s/${VAR_NAME}.*/${VAR_NAME}/" ${INPUT_DIR}/$1 > ${INPUT_DIR}/$1.tmp |
---|
142 | mv ${INPUT_DIR}/$1.tmp ${INPUT_DIR}/$1 |
---|
143 | sed -e "s/${VAR_NAME}/$2=$3/" ${INPUT_DIR}/$1 > ${INPUT_DIR}/$1.tmp |
---|
144 | mv ${INPUT_DIR}/$1.tmp ${INPUT_DIR}/$1 |
---|
145 | |
---|
146 | echo "finished script : set_namelist $@" >> ${SETTE_DIR}/output.sette |
---|
147 | echo "++++++++++++++++" >> ${SETTE_DIR}/output.sette |
---|
148 | echo " " >> ${SETTE_DIR}/output.sette |
---|
149 | } |
---|