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/NERC/dev_sette_NERC – NEMO

source: branches/NERC/dev_sette_NERC/all_functions.sh @ 13625

Last change on this file since 13625 was 13625, checked in by smueller, 4 years ago

Adjustment of the MEDUSA-specific extension of the test for local working-copy modifications in SETTE

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 17.6 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
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#  $ 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      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# define validation dir
94set_valid_dir () {
95    LANG=en_US
96    REVISION_NB=`LC_MESSAGES=${LANG} ${SVN_CMD} info ${SETTE_DIR}/.. | grep "Last Changed Rev" | awk '{print $NF}'`
97    if [ ${#REVISION_NB} -eq 0 ]
98    then
99        echo "some problems with ${SVN_CMD} info command"
100        echo "some problems with ${SVN_CMD} info command" >> ${SETTE_DIR}/output.sette
101        REVISION_NB=`date +%Y%m%d`
102        echo "put in ${REVISION_NB} date"
103        echo "put in ${REVISION_NB} date" >> ${SETTE_DIR}/output.sette
104    else
105    echo "value of revision number of NEMOGCM: ${REVISION_NB}"
106    fi
107    # detect local modifications (one MEDUSA-specific exception)
108    [ `${SVN_CMD} status -q ${SETTE_DIR}/../{cfg,tests,src,src/TOP/MEDUSA,cfgs/SHARED_MEDUSA,cfgs/ORCA2_MEDUSA} | grep -v '~.*/tests/BENCH/EXPREF/namelist_top_cfg' | wc -l` -ge 1 ] && REVISION_NB=${REVISION_NB}+
109    NEMO_VALID=${NEMO_VALIDATION_DIR}/W${NEW_CONF}/${CMP_NAM}/${REVISION_NB}/${TEST_NAME}
110}
111
112# clean valid dir (move old ocean_output/run.stat and tracer to avoid checking them in case something wrong happen.
113clean_valid_dir () {
114#   set_valid_dir # already done in sette_ref/sette_test
115   echo "validation directory is : $NEMO_VALID"
116   if [ -d $NEMO_VALID ] ; then
117      [ -f ${NEMO_VALID}/ocean.output ] && mv ${NEMO_VALID}/ocean.output ${NEMO_VALID}/ocean.output_old
118      [ -f ${NEMO_VALID}/run.stat ]     && mv ${NEMO_VALID}/run.stat     ${NEMO_VALID}/run.stat_old
119      [ -f ${NEMO_VALID}/tracer.stat ]  && mv ${NEMO_VALID}/tracer.stat  ${NEMO_VALID}/tracer.stat_old
120   fi
121}
122
123# function to set namelists parameters
124set_namelist () {
125   minargcount=3
126   if [ ${#} -lt ${minargcount} ]
127   then
128      echo "not enough arguments for set_namelist"
129      echo "${usage}"
130      exit 1
131   fi
132   unset minargcount
133   if [  ! -f ${SETTE_DIR}/output.sette ] ; then
134                touch ${SETTE_DIR}/output.sette
135        fi
136
137        echo "executing script : set_namelist $@" >> ${SETTE_DIR}/output.sette
138        echo "################" >> ${SETTE_DIR}/output.sette
139     
140   VAR_NAME=$( supergrep $2 ${EXE_DIR}/$1 )
141   if [ ${#VAR_NAME} -eq 0 ] 
142   then
143      echo "doing \"set_namelist $@\". "  >> ${SETTE_DIR}/output.sette
144      echo "variable: \"$2\" not found in \"${EXE_DIR}/$1\" "  >> ${SETTE_DIR}/output.sette
145                NAMREF=$( basename $1 _cfg )_ref
146      echo "doing more : search in ${EXE_DIR}/$NAMREF " >> ${SETTE_DIR}/output.sette
147                VAR_NAME=$( supergrep $2 ${EXE_DIR}/$NAMREF )
148           if [ ${#VAR_NAME} -eq 0 ] 
149           then
150                    echo " variable $VAR_NAME not found in ${EXE_DIR}/$1 nor in ${EXE_DIR}/$NAMREF "
151                    echo " check your variable name "
152            echo "exit"
153            echo "error in executing script : set_namelist $@" >> ${SETTE_DIR}/output.sette
154            echo "....." >> ${SETTE_DIR}/output.sette
155            exit 1
156                fi
157                LINEVAR=$( grep -s -n "$VAR_NAME" ${EXE_DIR}/$NAMREF | awk -F: '{ { print $1} }' )
158                echo " $VAR_NAME found in ${EXE_DIR}/$NAMREF at line $LINEVAR " >> ${SETTE_DIR}/output.sette
159#   search for namelist group name
160                NAMGRP=$( head -n$LINEVAR ${EXE_DIR}/$NAMREF | grep --line-buffered "^&nam" | tail -1 | awk -F" " '{ { print $1} }' ) 
161                echo " variable $VAR_NAME will be added in $NAMGRP namelist-group of namelist file ${EXE_DIR}/$1 " >> ${SETTE_DIR}/output.sette
162# Add $VARNAME in namelist file ${EXE_DIR}/$1 in namelist group $NAMGRP
163# on mac osx, replace sed --posix by gsed (available with mac port)
164                sed --posix "/${NAMGRP} /a\ ${VAR_NAME} " ${EXE_DIR}/$1 > ${EXE_DIR}/$1.tmp || gsed --posix "/${NAMGRP} /a\ ${VAR_NAME} " ${EXE_DIR}/$1 > ${EXE_DIR}/$1.tmp
165# if file not empty replace ${EXE_DIR}/$1
166                if [ -s ${EXE_DIR}/$1.tmp ] ; then
167                   mv ${EXE_DIR}/$1.tmp ${EXE_DIR}/$1 
168                else
169                echo "file ${EXE_DIR}/$1.tmp is empty. sed command went wrong "; exit 200
170                fi
171   fi
172
173        ARGS_LST="${@:3}"
174        sed -e "s;${VAR_NAME}.*;${VAR_NAME};" ${EXE_DIR}/$1 > ${EXE_DIR}/$1.tmp
175        mv ${EXE_DIR}/$1.tmp ${EXE_DIR}/$1
176        sed -e "s;${VAR_NAME};$2=${ARGS_LST};"  ${EXE_DIR}/$1 > ${EXE_DIR}/$1.tmp
177        mv ${EXE_DIR}/$1.tmp ${EXE_DIR}/$1
178
179        echo "finished script : set_namelist $@" >> ${SETTE_DIR}/output.sette
180        echo "++++++++++++++++" >> ${SETTE_DIR}/output.sette
181        echo "                " >> ${SETTE_DIR}/output.sette
182}
183
184
185# function to tidy up after each test and populate the NEMO_VALIDATION store
186post_test_tidyup () {
187# Save current exit status of caller script
188    RUN_STATUS=$? 
189    echo "Exit status: ${RUN_STATUS}" 
190#
191# requires the following variables defined and exported from the calling script:
192#  SETTE_DIR
193#  INPUT_DIR
194#  EXE_DIR
195#  CONFIG_DIR
196#  NEMO_VALIDATION_DIR
197#  NEW_CONF
198#  CMP_NAM
199#  TEST_NAME
200echo "SETTE directory is : ${SETTE_DIR}"
201echo "INPUT directory is : ${INPUT_DIR}"
202echo "EXECUTION directory is : ${EXE_DIR}"
203echo "CONFIG directory is : ${CONFIG_DIR}"
204echo "VALIDATION directory is : ${NEMO_VALID}"
205echo "NEW CONFIGURATION is : ${NEW_CONF}"
206echo "COMPILER is : ${CMP_NAM}"
207echo "TEST is : ${TEST_NAME}"
208echo "TOOLS directory is : ${TOOLS_DIR}"
209################################################################
210# SMALL DEBUG
211    EXIT_STATUS=${RUN_STATUS}
212    if [ ! -r ${EXE_DIR}/ocean.output ]
213        then
214        grep "E R R O R" ${EXE_DIR}/ocean.output && echo "Some ERRORS at execution time, see ${EXE_DIR}/ocean.output"
215        EXIT_STATUS=2
216        # exit 2 Error now catch in the report
217    fi
218
219    if [ ! -r ${EXE_DIR}/time.step ]
220        then
221        echo "file time.step does not exist"   >> ${SETTE_DIR}/output.sette
222        echo "some problems during execution of model"  >> ${SETTE_DIR}/output.sette
223        EXIT_STATUS=1
224        # exit 1 Error now catch in the report
225    else
226        echo "file time.step exists"  >> ${SETTE_DIR}/output.sette
227        echo "execution of model time step loop started"   >> ${SETTE_DIR}/output.sette
228    fi
229
230################################################################
231
232################################################################
233#
234# Creation of NEMO_VALIDATION tree
235#    set_valid_dir already done in sette_reference_config
236    mkdir -p ${NEMO_VALIDATION_DIR}
237    if [ -d ${NEMO_VALIDATION_DIR} ] ; then
238   echo "created ${NEMO_VALIDATION_DIR} directory"   >> ${SETTE_DIR}/output.sette
239    else
240   echo "problems in creating ${NEMO_VALIDATION_DIR} directory"   >> ${SETTE_DIR}/output.sette
241   echo "EXIT,"
242   exit 1
243    fi
244#
245# Exit before populating validation directory if the model run has
246# returned a non-zero exit status
247# On CRAY NEMO exit is not the expected 999 or 123456 (let this bloc in case useful later on).
248#    case ${EXIT_STATUS} in
249#        0|123456|999) echo " NEMO finished with exit code $EXIT_STATUS " ; post_test_tidyup ;;
250#        *) echo " NEMO abort on an unexpected error (segmentation fault or whatever) $EXIT_STATUS "
251#    esac
252
253    [ ${EXIT_STATUS} -ne 0 ] && exit ${EXIT_STATUS} 
254#
255# Save output & debug files in NEMO_VALIDATION tree
256    echo "saving ocean & ice output, run.stat, tracer.stat files ...." >> ${SETTE_DIR}/output.sette
257    echo "            " >> ${SETTE_DIR}/output.sette
258    [ -f ${EXE_DIR}/ocean.output ] && cp ${EXE_DIR}/*ocean.output ${NEMO_VALIDATION_DIR}/.
259    [ -f ${EXE_DIR}/run.stat ] && cp ${EXE_DIR}/*run.stat ${NEMO_VALIDATION_DIR}/.
260    [ -f ${EXE_DIR}/output.namelist.dyn ] && cp ${EXE_DIR}/*output.nam* ${NEMO_VALIDATION_DIR}/.
261    [ -f ${EXE_DIR}/tracer.stat ] && cp ${EXE_DIR}/*tracer.stat ${NEMO_VALIDATION_DIR}/.
262
263    if [ -n "$(ls ${NEMO_VALIDATION_DIR}/*run*)" ] ; then
264   echo "moved run.stat in ${NEMO_VALIDATION_DIR} directory"  >> ${SETTE_DIR}/output.sette
265   echo "moved run.stat in ${NEMO_VALIDATION_DIR} directory" 
266    else
267   echo "problem in looking for run.stat file in ${NEMO_VALIDATION_DIR} directory"  >> ${SETTE_DIR}/output.sette
268   echo "run.stat IS NOT in ${NEMO_VALIDATION_DIR} directory" 
269    fi
270    if [ -n "$(ls ${NEMO_VALIDATION_DIR}/*ocean.output*)" ] ; then
271   echo "moved ocean.output in ${NEMO_VALIDATION_DIR} directory"  >> ${SETTE_DIR}/output.sette
272   echo "moved ocean.output in ${NEMO_VALIDATION_DIR} directory" 
273    else
274   echo "problem in looking for ocean.output file in ${NEMO_VALIDATION_DIR} directory"  >> ${SETTE_DIR}/output.sette
275   echo "ocean.output IS NOT in ${NEMO_VALIDATION_DIR} directory" 
276    fi
277    if [ -n "$(ls ${NEMO_VALIDATION_DIR}/*tracer.stat*)" ] ; then
278        echo "moved tracer.stat in ${NEMO_VALIDATION_DIR} directory"  >> ${SETTE_DIR}/output.sette
279        echo "moved tracer.stat in ${NEMO_VALIDATION_DIR} directory"
280    else
281        echo "problem in looking for tracer.stat file in ${NEMO_VALIDATION_DIR} directory"  >> ${SETTE_DIR}/output.sette
282        echo "tracer.stat IS NOT in ${NEMO_VALIDATION_DIR} directory"
283    fi
284}
285
286#############################################################
287# extra functions to manipulate settings in the iodef.xml file
288#
289# Examples:
290#   set_xio_file_type    iodef.xml one_file
291#   set_xio_using_server iodef.xml true
292#   set_xio_buffer_size  iodef.xml 50000000
293#   set_xio_field_defs   iodef.xml
294#
295#############################################################
296
297usage2=" Usage : set_xio_file_type input_iodef.xml one_file||multiple_file"
298usage3=" Usage : set_xio_using_server input_iodef.xml true||false"
299usage4=" Usage : set_xio_buffer_size input_iodef.xml int_buffer_size"
300usage5=" Usage : set_xio_field_defs input_iodef.xml"
301
302set_xio_file_type () {
303        minargcount=2
304        if [ ${#} -lt ${minargcount} ]
305        then
306                echo "not enough arguments for set_xio_file_type"
307                echo "${usage2}"
308                exit 1
309        fi
310        if [ $2 != "one_file" ] && [ $2 != "multiple_file" ]
311        then
312                echo "unrecognised argument for set_xio_file_type"
313                echo "${usage2}"
314                echo $2
315                exit 1
316        fi
317        unset minargcount
318        if [  ! -f ${SETTE_DIR}/output.sette ] ; then
319                touch ${SETTE_DIR}/output.sette
320        fi
321
322        echo "executing script : set_xio_file_type $@" >> ${SETTE_DIR}/output.sette
323        echo "################" >> ${SETTE_DIR}/output.sette
324
325        VAR_NAME=$( grep "^.*<.*file_definition.*type.*=" ${EXE_DIR}/$1 | sed -e "s% *\!.*%%" )
326        if [ ${#VAR_NAME} -eq 0 ]
327        then
328                echo "doing \"set_xio_file_type $@\". "
329                echo "xml_tag: file_definition with variable: type is empty"
330                echo "confirm that an appropriate file_definition is in \"${EXE_DIR}/$1\" "
331                echo "exit"
332                echo "error in executing script : set_xio_file_type $@" >> ${SETTE_DIR}/output.sette
333                echo "....." >> ${SETTE_DIR}/output.sette
334                exit 1
335        fi
336        if [ $2 == "one_file" ] 
337        then
338           sed -e "s:multiple_file:one_file:" ${EXE_DIR}/$1 > ${EXE_DIR}/$1.tmp
339        else
340           sed -e "s:one_file:multiple_file:" ${EXE_DIR}/$1 > ${EXE_DIR}/$1.tmp
341        fi
342        mv ${EXE_DIR}/$1.tmp ${EXE_DIR}/$1
343
344        echo "finished script : set_xio_file_type $@" >> ${SETTE_DIR}/output.sette
345        echo "++++++++++++++++" >> ${SETTE_DIR}/output.sette
346        echo "                " >> ${SETTE_DIR}/output.sette
347}
348
349set_xio_using_server () {
350        minargcount=2
351        if [ ${#} -lt ${minargcount} ]
352        then
353                echo "not enough arguments for set_xio_using_server"
354                echo "${usage2}"
355                exit 1
356        fi
357        if [ $2 != "true" ] && [ $2 != "false" ]
358        then
359                echo "unrecognised argument for set_xio_using_server"
360                echo "${usage2}"
361                echo $2
362                exit 1
363        fi
364        unset minargcount
365        if [  ! -f ${SETTE_DIR}/output.sette ] ; then
366                touch ${SETTE_DIR}/output.sette
367        fi
368
369        echo "executing script : set_xio_using_server $@" >> ${SETTE_DIR}/output.sette
370        echo "################" >> ${SETTE_DIR}/output.sette
371
372        VAR_NAME=$( grep "^.*<.*variable id.*=.*using_server.*=.*bool" ${EXE_DIR}/$1 | sed -e "s% *\!.*%%" )
373        if [ ${#VAR_NAME} -eq 0 ]
374        then
375                echo "doing \"set_xio_using_server $@\". "
376                echo "xml_tag: "variable id=using_server" with variable: bool is empty"
377                echo "confirm that an appropriate variable id is in \"${EXE_DIR}/$1\" "
378                echo "exit"
379                echo "error in executing script : set_xio_using_server $@" >> ${SETTE_DIR}/output.sette
380                echo "....." >> ${SETTE_DIR}/output.sette
381                exit 1
382        fi
383        if [ $2 == "false" ]
384        then
385           sed -e "/using_server/s:true:false:" ${EXE_DIR}/$1 > ${EXE_DIR}/$1.tmp
386           export USING_MPMD=no
387        else
388           sed -e "/using_server/s:false:true:" ${EXE_DIR}/$1 > ${EXE_DIR}/$1.tmp
389           export USING_MPMD=yes
390        fi
391        mv ${EXE_DIR}/$1.tmp ${EXE_DIR}/$1
392
393        echo "finished script : set_xio_using_server $@" >> ${SETTE_DIR}/output.sette
394        echo "++++++++++++++++" >> ${SETTE_DIR}/output.sette
395        echo "                " >> ${SETTE_DIR}/output.sette
396}
397
398set_xio_buffer_size () {
399        minargcount=2
400        if [ ${#} -lt ${minargcount} ]
401        then
402                echo "not enough arguments for set_xio_buffer_size"
403                echo "${usage4}"
404                exit 1
405        fi
406        unset minargcount
407        if [  ! -f ${SETTE_DIR}/output.sette ] ; then
408                touch ${SETTE_DIR}/output.sette
409        fi
410
411        echo "executing script : set_xio_buffer_size $@" >> ${SETTE_DIR}/output.sette
412        echo "################" >> ${SETTE_DIR}/output.sette
413
414        VAR_NAME=$( grep "^.*<.*variable id.*=.*buffer_size.*=.*integer" ${EXE_DIR}/$1 | sed -e "s% *\!.*%%" )
415        if [ ${#VAR_NAME} -eq 0 ]
416        then
417                echo "doing \"set_xio_buffer_size $@\". "
418                echo "xml_tag: "variable id=buffer_size" with variable: integer is empty"
419                echo "confirm that an appropriate variable id is in \"${EXE_DIR}/$1\" "
420                echo "exit"
421                echo "error in executing script : set_xio_buffer_size $@" >> ${SETTE_DIR}/output.sette
422                echo "....." >> ${SETTE_DIR}/output.sette
423                exit 1
424        fi
425        sed -e "/buffer_size/s:>.*<:>$2<:" ${EXE_DIR}/$1 > ${EXE_DIR}/$1.tmp
426        mv ${EXE_DIR}/$1.tmp ${EXE_DIR}/$1
427
428        echo "finished script : set_xio_buffer_size $@" >> ${SETTE_DIR}/output.sette
429        echo "++++++++++++++++" >> ${SETTE_DIR}/output.sette
430        echo "                " >> ${SETTE_DIR}/output.sette
431}
432
433set_xio_field_defs () {
434        minargcount=1
435        if [ ${#} -lt ${minargcount} ]
436        then
437                echo "not enough arguments for set_xio_field_defs"
438                echo "${usage5}"
439                exit 1
440        fi
441        unset minargcount
442        if [  ! -f ${SETTE_DIR}/output.sette ] ; then
443                touch ${SETTE_DIR}/output.sette
444        fi
445
446        echo "executing script : set_xio_field_defs $@" >> ${SETTE_DIR}/output.sette
447        echo "################" >> ${SETTE_DIR}/output.sette
448
449
450        [ -f ${EXE_DIR}/field_def_nemo-oce.xml ] || sed -i '/field_def_nemo-oce/d' $1
451        [ -f ${EXE_DIR}/field_def_nemo-ice.xml ] || sed -i '/field_def_nemo-ice/d' $1
452        [ -f ${EXE_DIR}/field_def_nemo-pisces.xml ] || sed -i '/field_def_nemo-pisces/d' $1
453
454        echo "finished script : set_xio_field_defs $@" >> ${SETTE_DIR}/output.sette
455        echo "++++++++++++++++" >> ${SETTE_DIR}/output.sette
456        echo "                " >> ${SETTE_DIR}/output.sette
457}
Note: See TracBrowser for help on using the repository browser.