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/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/SETTE – NEMO

source: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/SETTE/all_functions.sh @ 8873

Last change on this file since 8873 was 4233, checked in by cbricaud, 11 years ago

commit dev_r3948_NOC_FK into dev_MERCATOR_UKMO_2013

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 12.9 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 INPUT_NAMELIST VARIABLE VALUE
33#  $ post_test_tidyup
34#
35#
36# DESCRIPTION
37# ===========
38#
39# function superegrep
40#   input variable value
41#
42# function set_namelist
43#   input namelist_name variable value
44#   output namelist
45#
46# function post_test_tidyup
47#   creates nemo_validation tree, and save output & debug files
48#   this function creates tree of validation in NEMO_VALIDATION_DIR as follows :
49#
50# NEMO_VALIDATION_DIR/WCONFIG_NAME/WCOMPILER_NAME/REVISION_NUMBER(or DATE)/TEST_NAME
51#
52# NEMO_VALIDATION_DIR           : is choosen in param.cfg
53#
54# WCONFIG_NAME                  : set by makenemo at the moment of compilation
55#
56# WCOMPILER_NAME                : set by makenemo at the moment of compilation
57#
58# REVISION_NUMBER(or DATE)      : revision number by svn info, if problems with svn date is taken
59#
60# TEST_NAME                     : set in sette.sh for each configuration to be tested (directory TEST_NAME is created under ${NEW_CONF} directory )
61#
62# EXAMPLES
63# ========
64#
65# ::
66#
67#  $ ./set_namelist namelist          nn_itend        75
68#  $ ./set_namelist namelist_ice_lim2 cn_icerst_in  \"00101231_restart_ice\"
69#  $ post_test_tidyup
70#
71#
72# TODO
73# ====
74#
75# option debug
76#
77#
78# EVOLUTIONS
79# ==========
80#
81# $Id$
82#
83#   * creation
84#-
85# function to find namelists parameters
86supergrep () {
87            grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%"
88    }
89
90usage=" Usage : set_namelist input_namelist variable_name value"
91usage=" if value is a string ths is neede syntax : ./set_namelist namelist_name var_name \"new_value\" "
92
93# function to set namelists parameters
94set_namelist () {
95   minargcount=3
96   if [ ${#} -lt ${minargcount} ]
97   then
98      echo "not enough arguments for set_namelist"
99      echo "${usage}"
100      exit 1
101   fi
102   unset minargcount
103   if [  ! -f ${SETTE_DIR}/output.sette ] ; then
104                touch ${SETTE_DIR}/output.sette
105        fi
106
107        echo "executing script : set_namelist $@" >> ${SETTE_DIR}/output.sette
108        echo "################" >> ${SETTE_DIR}/output.sette
109     
110   VAR_NAME=$( supergrep $2 ${EXE_DIR}/$1 )
111   if [ ${#VAR_NAME} -eq 0 ] 
112   then
113      echo "doing \"set_namelist $@\". "
114      echo "variable: \"$2\" is empty"
115      echo "confirm that variable $2 is in \"${EXE_DIR}/$1\" "
116      echo "exit"
117      echo "error in executing script : set_namelist $@" >> ${SETTE_DIR}/output.sette
118      echo "....." >> ${SETTE_DIR}/output.sette
119      exit 1
120   fi
121        sed -e "s:${VAR_NAME}.*:${VAR_NAME}:" ${EXE_DIR}/$1 > ${EXE_DIR}/$1.tmp
122        mv ${EXE_DIR}/$1.tmp ${EXE_DIR}/$1
123        sed -e "s:${VAR_NAME}:$2=$3:"  ${EXE_DIR}/$1 > ${EXE_DIR}/$1.tmp
124        mv ${EXE_DIR}/$1.tmp ${EXE_DIR}/$1
125
126        echo "finished script : set_namelist $@" >> ${SETTE_DIR}/output.sette
127        echo "++++++++++++++++" >> ${SETTE_DIR}/output.sette
128        echo "                " >> ${SETTE_DIR}/output.sette
129}
130
131
132# function to tidy up after each test and populate the NEMO_VALIDATION store
133post_test_tidyup () {
134#
135# requires the following variables defined and exported from the calling script:
136#  SETTE_DIR
137#  INPUT_DIR
138#  EXE_DIR
139#  CONFIG_DIR
140#  NEMO_VALIDATION_DIR
141#  NEW_CONF
142#  CMP_NAM
143#  TEST_NAME
144echo "SETTE directory is : ${SETTE_DIR}"
145echo "INPUT directory is : ${INPUT_DIR}"
146echo "EXECUTION directory is : ${EXE_DIR}"
147echo "CONFIG directory is : ${CONFIG_DIR}"
148echo "VALIDATION directory is : ${NEMO_VALIDATION_DIR}"
149echo "NEW CONFIGURATION is : ${NEW_CONF}"
150echo "COMPILER is : ${CMP_NAM}"
151echo "TEST is : ${TEST_NAME}"
152################################################################
153# SMALL DEBUG
154    if [ ! -r ${EXE_DIR}/time.step ]
155        then
156        echo "file time.step does not exist"   >> ${SETTE_DIR}/output.sette
157        echo "some problems during execution of model"  >> ${SETTE_DIR}/output.sette
158        exit 1
159    else
160        echo "file time.step exists"  >> ${SETTE_DIR}/output.sette
161        echo "ok model run"   >> ${SETTE_DIR}/output.sette
162    fi
163################################################################
164
165################################################################
166# Creation of NEMO_VALIDATION tree
167    export LANG=en_US
168    cd ${CONFIG_DIR}
169    cd ../
170    REVISION_NB=`svn info | grep -i "Revision:" | sed -e "s/ //" | cut -d ":" -f 2`
171    if [ ${#REVISION_NB} -eq 0 ]
172    then
173      echo "some problems with svn info command"
174      echo "some problems with svn info command" >> ${SETTE_DIR}/output.sette
175      REVISION_NB=`date +%Y%m%d`
176      echo "put in ${REVISION_NB} date"
177      echo "put in ${REVISION_NB} date" >> ${SETTE_DIR}/output.sette
178    else
179    echo "value of revision number of NEMOGCM: ${REVISION_NB}"
180    fi
181    cd ${NEMO_VALIDATION_DIR}
182    `mkdir -p ${NEMO_VALIDATION_DIR}/W${NEW_CONF}/${CMP_NAM}/${REVISION_NB}/${TEST_NAME}`
183    NEMO_VALID=${NEMO_VALIDATION_DIR}/W${NEW_CONF}/${CMP_NAM}/${REVISION_NB}/${TEST_NAME}
184    if [ -d ${NEMO_VALID} ] ; then
185   echo "created ${NEMO_VALID} directory"   >> ${SETTE_DIR}/output.sette
186    else
187   echo "problems in creating ${NEMO_VALID} directory"   >> ${SETTE_DIR}/output.sette
188   echo "EXIT,"
189   exit 1
190    fi
191    # Save output & debug files in NEMO_VALIDATION tree
192    echo "saving ocean & ice output, solver.stat, tracer.stat files ...." >> ${SETTE_DIR}/output.sette
193    echo "            " >> ${SETTE_DIR}/output.sette
194    [ -f ${EXE_DIR}/*ocean.output ] && cp ${EXE_DIR}/*ocean.output ${NEMO_VALID}/.
195    [ -f ${EXE_DIR}/*solver.stat ] && cp ${EXE_DIR}/*solver.stat ${NEMO_VALID}/.
196    [ -f ${EXE_DIR}/*tracer.stat ] && cp ${EXE_DIR}/*tracer.stat ${NEMO_VALID}/.
197    if [ -n "$(ls ${NEMO_VALID}/*solver*)" ] ; then
198   echo "moved solver.stat in ${NEMO_VALID} directory"  >> ${SETTE_DIR}/output.sette
199   echo "moved solver.stat in ${NEMO_VALID} directory" 
200    else
201   echo "problem in looking for solver.stat file in ${NEMO_VALID} directory"  >> ${SETTE_DIR}/output.sette
202   echo "solver.stat IS NOT in ${NEMO_VALID} directory" 
203    fi
204    if [ -n "$(ls ${NEMO_VALID}/*ocean.output*)" ] ; then
205   echo "moved ocean.output in ${NEMO_VALID} directory"  >> ${SETTE_DIR}/output.sette
206   echo "moved ocean.output in ${NEMO_VALID} directory" 
207    else
208   echo "problem in looking for ocean.output file in ${NEMO_VALID} directory"  >> ${SETTE_DIR}/output.sette
209   echo "ocean.output IS NOT in ${NEMO_VALID} directory" 
210    fi
211    if [ -n "$(ls ${NEMO_VALID}/*tracer.stat*)" ] ; then
212        echo "moved tracer.stat in ${NEMO_VALID} directory"  >> ${SETTE_DIR}/output.sette
213        echo "moved tracer.stat in ${NEMO_VALID} directory"
214    else
215        echo "problem in looking for tracer.stat file in ${NEMO_VALID} directory"  >> ${SETTE_DIR}/output.sette
216        echo "tracer.stat IS NOT in ${NEMO_VALID} directory"
217    fi
218}
219
220#############################################################
221# extra functions to manipulate settings in the iodef.xml file
222#
223# Examples:
224#   set_xio_file_type    iodef.xml one_file
225#   set_xio_using_server iodef.xml true
226#   set_xio_buffer_size  iodef.xml 50000000
227#
228#############################################################
229
230usage2=" Usage : set_xio_file_type input_iodef.xml one_file||multiple_file"
231usage3=" Usage : set_xio_using_server input_iodef.xml true||false"
232usage4=" Usage : set_xio_buffer_size input_iodef.xml int_buffer_size"
233
234set_xio_file_type () {
235        minargcount=2
236        if [ ${#} -lt ${minargcount} ]
237        then
238                echo "not enough arguments for set_xio_file_type"
239                echo "${usage2}"
240                exit 1
241        fi
242        if [ $2 != "one_file" ] && [ $2 != "multiple_file" ]
243        then
244                echo "unrecognised argument for set_xio_file_type"
245                echo "${usage2}"
246                echo $2
247                exit 1
248        fi
249        unset minargcount
250        if [  ! -f ${SETTE_DIR}/output.sette ] ; then
251                touch ${SETTE_DIR}/output.sette
252        fi
253
254        echo "executing script : set_xio_file_type $@" >> ${SETTE_DIR}/output.sette
255        echo "################" >> ${SETTE_DIR}/output.sette
256
257        VAR_NAME=$( grep "^.*<.*file_definition.*type.*=" ${EXE_DIR}/$1 | sed -e "s% *\!.*%%" )
258        if [ ${#VAR_NAME} -eq 0 ]
259        then
260                echo "doing \"set_xio_file_type $@\". "
261                echo "xml_tag: file_definition with variable: type is empty"
262                echo "confirm that an appropriate file_definition is in \"${EXE_DIR}/$1\" "
263                echo "exit"
264                echo "error in executing script : set_xio_file_type $@" >> ${SETTE_DIR}/output.sette
265                echo "....." >> ${SETTE_DIR}/output.sette
266                exit 1
267        fi
268        if [ $2 == "one_file" ] 
269        then
270           sed -e "s:multiple_file:one_file:" ${EXE_DIR}/$1 > ${EXE_DIR}/$1.tmp
271        else
272           sed -e "s:one_file:multiple_file:" ${EXE_DIR}/$1 > ${EXE_DIR}/$1.tmp
273        fi
274        mv ${EXE_DIR}/$1.tmp ${EXE_DIR}/$1
275
276        echo "finished script : set_xio_file_type $@" >> ${SETTE_DIR}/output.sette
277        echo "++++++++++++++++" >> ${SETTE_DIR}/output.sette
278        echo "                " >> ${SETTE_DIR}/output.sette
279}
280
281set_xio_using_server () {
282        minargcount=2
283        if [ ${#} -lt ${minargcount} ]
284        then
285                echo "not enough arguments for set_xio_using_server"
286                echo "${usage2}"
287                exit 1
288        fi
289        if [ $2 != "true" ] && [ $2 != "false" ]
290        then
291                echo "unrecognised argument for set_xio_using_server"
292                echo "${usage2}"
293                echo $2
294                exit 1
295        fi
296        unset minargcount
297        if [  ! -f ${SETTE_DIR}/output.sette ] ; then
298                touch ${SETTE_DIR}/output.sette
299        fi
300
301        echo "executing script : set_xio_using_server $@" >> ${SETTE_DIR}/output.sette
302        echo "################" >> ${SETTE_DIR}/output.sette
303
304        VAR_NAME=$( grep "^.*<.*variable id.*=.*using_server.*=.*boolean" ${EXE_DIR}/$1 | sed -e "s% *\!.*%%" )
305        if [ ${#VAR_NAME} -eq 0 ]
306        then
307                echo "doing \"set_xio_using_server $@\". "
308                echo "xml_tag: "variable id=using_server" with variable: boolean is empty"
309                echo "confirm that an appropriate variable id is in \"${EXE_DIR}/$1\" "
310                echo "exit"
311                echo "error in executing script : set_xio_using_server $@" >> ${SETTE_DIR}/output.sette
312                echo "....." >> ${SETTE_DIR}/output.sette
313                exit 1
314        fi
315        if [ $2 == "false" ]
316        then
317           sed -e "/using_server/s:true:false:" ${EXE_DIR}/$1 > ${EXE_DIR}/$1.tmp
318           export USING_MPMD=no
319        else
320           sed -e "/using_server/s:false:true:" ${EXE_DIR}/$1 > ${EXE_DIR}/$1.tmp
321           export USING_MPMD=yes
322        fi
323        mv ${EXE_DIR}/$1.tmp ${EXE_DIR}/$1
324
325        echo "finished script : set_xio_using_server $@" >> ${SETTE_DIR}/output.sette
326        echo "++++++++++++++++" >> ${SETTE_DIR}/output.sette
327        echo "                " >> ${SETTE_DIR}/output.sette
328}
329
330set_xio_buffer_size () {
331        minargcount=2
332        if [ ${#} -lt ${minargcount} ]
333        then
334                echo "not enough arguments for set_xio_buffer_size"
335                echo "${usage4}"
336                exit 1
337        fi
338        unset minargcount
339        if [  ! -f ${SETTE_DIR}/output.sette ] ; then
340                touch ${SETTE_DIR}/output.sette
341        fi
342
343        echo "executing script : set_xio_buffer_size $@" >> ${SETTE_DIR}/output.sette
344        echo "################" >> ${SETTE_DIR}/output.sette
345
346        VAR_NAME=$( grep "^.*<.*variable id.*=.*buffer_size.*=.*integer" ${EXE_DIR}/$1 | sed -e "s% *\!.*%%" )
347        if [ ${#VAR_NAME} -eq 0 ]
348        then
349                echo "doing \"set_xio_buffer_size $@\". "
350                echo "xml_tag: "variable id=buffer_size" with variable: integer is empty"
351                echo "confirm that an appropriate variable id is in \"${EXE_DIR}/$1\" "
352                echo "exit"
353                echo "error in executing script : set_xio_buffer_size $@" >> ${SETTE_DIR}/output.sette
354                echo "....." >> ${SETTE_DIR}/output.sette
355                exit 1
356        fi
357        sed -e "/buffer_size/s:>.*<:>$2<:" ${EXE_DIR}/$1 > ${EXE_DIR}/$1.tmp
358        mv ${EXE_DIR}/$1.tmp ${EXE_DIR}/$1
359
360        echo "finished script : set_xio_buffer_size $@" >> ${SETTE_DIR}/output.sette
361        echo "++++++++++++++++" >> ${SETTE_DIR}/output.sette
362        echo "                " >> ${SETTE_DIR}/output.sette
363}
364
Note: See TracBrowser for help on using the repository browser.