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 NEMO/branches/2019/fix_sette_ticket2239 – NEMO

source: NEMO/branches/2019/fix_sette_ticket2239/all_functions.sh @ 11036

Last change on this file since 11036 was 10755, checked in by mathiot, 5 years ago

changes to avoid messup the validation directory revision number in case revision of the src is changed between the start and the end of the sette job + change order of the config in param to start the slowest config first

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