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 @ 10698

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

check exit code from NEMO (do not copy anything if it failed on exit code other than 0/123456/999) + rename run.stat/tracer.stat/ocean.output to *_old in the current validation dir (ticket #2239)

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 16.4 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
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#
186# requires the following variables defined and exported from the calling script:
187#  SETTE_DIR
188#  INPUT_DIR
189#  EXE_DIR
190#  CONFIG_DIR
191#  NEMO_VALIDATION_DIR
192#  NEW_CONF
193#  CMP_NAM
194#  TEST_NAME
195echo "SETTE directory is : ${SETTE_DIR}"
196echo "INPUT directory is : ${INPUT_DIR}"
197echo "EXECUTION directory is : ${EXE_DIR}"
198echo "CONFIG directory is : ${CONFIG_DIR}"
199echo "VALIDATION directory is : ${NEMO_VALIDATION_DIR}"
200echo "NEW CONFIGURATION is : ${NEW_CONF}"
201echo "COMPILER is : ${CMP_NAM}"
202echo "TEST is : ${TEST_NAME}"
203echo "TOOLS directory is : ${TOOLS_DIR}"
204################################################################
205# SMALL DEBUG
206    if [ ! -r ${EXE_DIR}/ocean.output ]
207        then
208        grep "E R R O R" ${EXE_DIR}/ocean.output && echo "Some ERRORS at execution time, see ${EXE_DIR}/ocean.output"
209        # exit 2 Error now catch in the report
210    fi
211
212    if [ ! -r ${EXE_DIR}/time.step ]
213        then
214        echo "file time.step does not exist"   >> ${SETTE_DIR}/output.sette
215        echo "some problems during execution of model"  >> ${SETTE_DIR}/output.sette
216        # exit 1 Error now catch in the report
217    else
218        echo "file time.step exists"  >> ${SETTE_DIR}/output.sette
219        echo "execution of model time step loop started"   >> ${SETTE_DIR}/output.sette
220    fi
221
222################################################################
223
224################################################################
225#
226# Creation of NEMO_VALIDATION tree
227    set_valid_dir
228    mkdir -p ${NEMO_VALID}
229    if [ -d ${NEMO_VALID} ] ; then
230   echo "created ${NEMO_VALID} directory"   >> ${SETTE_DIR}/output.sette
231    else
232   echo "problems in creating ${NEMO_VALID} directory"   >> ${SETTE_DIR}/output.sette
233   echo "EXIT,"
234   exit 1
235    fi
236#
237# Save output & debug files in NEMO_VALIDATION tree
238    echo "saving ocean & ice output, run.stat, tracer.stat files ...." >> ${SETTE_DIR}/output.sette
239    echo "            " >> ${SETTE_DIR}/output.sette
240    [ -f ${EXE_DIR}/ocean.output ] && cp ${EXE_DIR}/*ocean.output ${NEMO_VALID}/.
241    [ -f ${EXE_DIR}/run.stat ] && cp ${EXE_DIR}/*run.stat ${NEMO_VALID}/.
242    [ -f ${EXE_DIR}/output.namelist.dyn ] && cp ${EXE_DIR}/*output.nam* ${NEMO_VALID}/.
243    [ -f ${EXE_DIR}/tracer.stat ] && cp ${EXE_DIR}/*tracer.stat ${NEMO_VALID}/.
244
245    if [ -n "$(ls ${NEMO_VALID}/*run*)" ] ; then
246   echo "moved run.stat in ${NEMO_VALID} directory"  >> ${SETTE_DIR}/output.sette
247   echo "moved run.stat in ${NEMO_VALID} directory" 
248    else
249   echo "problem in looking for run.stat file in ${NEMO_VALID} directory"  >> ${SETTE_DIR}/output.sette
250   echo "run.stat IS NOT in ${NEMO_VALID} directory" 
251    fi
252    if [ -n "$(ls ${NEMO_VALID}/*ocean.output*)" ] ; then
253   echo "moved ocean.output in ${NEMO_VALID} directory"  >> ${SETTE_DIR}/output.sette
254   echo "moved ocean.output in ${NEMO_VALID} directory" 
255    else
256   echo "problem in looking for ocean.output file in ${NEMO_VALID} directory"  >> ${SETTE_DIR}/output.sette
257   echo "ocean.output IS NOT in ${NEMO_VALID} directory" 
258    fi
259    if [ -n "$(ls ${NEMO_VALID}/*tracer.stat*)" ] ; then
260        echo "moved tracer.stat in ${NEMO_VALID} directory"  >> ${SETTE_DIR}/output.sette
261        echo "moved tracer.stat in ${NEMO_VALID} directory"
262    else
263        echo "problem in looking for tracer.stat file in ${NEMO_VALID} directory"  >> ${SETTE_DIR}/output.sette
264        echo "tracer.stat IS NOT in ${NEMO_VALID} directory"
265    fi
266}
267
268#############################################################
269# extra functions to manipulate settings in the iodef.xml file
270#
271# Examples:
272#   set_xio_file_type    iodef.xml one_file
273#   set_xio_using_server iodef.xml true
274#   set_xio_buffer_size  iodef.xml 50000000
275#   set_xio_field_defs   iodef.xml
276#
277#############################################################
278
279usage2=" Usage : set_xio_file_type input_iodef.xml one_file||multiple_file"
280usage3=" Usage : set_xio_using_server input_iodef.xml true||false"
281usage4=" Usage : set_xio_buffer_size input_iodef.xml int_buffer_size"
282usage5=" Usage : set_xio_field_defs input_iodef.xml"
283
284set_xio_file_type () {
285        minargcount=2
286        if [ ${#} -lt ${minargcount} ]
287        then
288                echo "not enough arguments for set_xio_file_type"
289                echo "${usage2}"
290                exit 1
291        fi
292        if [ $2 != "one_file" ] && [ $2 != "multiple_file" ]
293        then
294                echo "unrecognised argument for set_xio_file_type"
295                echo "${usage2}"
296                echo $2
297                exit 1
298        fi
299        unset minargcount
300        if [  ! -f ${SETTE_DIR}/output.sette ] ; then
301                touch ${SETTE_DIR}/output.sette
302        fi
303
304        echo "executing script : set_xio_file_type $@" >> ${SETTE_DIR}/output.sette
305        echo "################" >> ${SETTE_DIR}/output.sette
306
307        VAR_NAME=$( grep "^.*<.*file_definition.*type.*=" ${EXE_DIR}/$1 | sed -e "s% *\!.*%%" )
308        if [ ${#VAR_NAME} -eq 0 ]
309        then
310                echo "doing \"set_xio_file_type $@\". "
311                echo "xml_tag: file_definition with variable: type is empty"
312                echo "confirm that an appropriate file_definition is in \"${EXE_DIR}/$1\" "
313                echo "exit"
314                echo "error in executing script : set_xio_file_type $@" >> ${SETTE_DIR}/output.sette
315                echo "....." >> ${SETTE_DIR}/output.sette
316                exit 1
317        fi
318        if [ $2 == "one_file" ] 
319        then
320           sed -e "s:multiple_file:one_file:" ${EXE_DIR}/$1 > ${EXE_DIR}/$1.tmp
321        else
322           sed -e "s:one_file:multiple_file:" ${EXE_DIR}/$1 > ${EXE_DIR}/$1.tmp
323        fi
324        mv ${EXE_DIR}/$1.tmp ${EXE_DIR}/$1
325
326        echo "finished script : set_xio_file_type $@" >> ${SETTE_DIR}/output.sette
327        echo "++++++++++++++++" >> ${SETTE_DIR}/output.sette
328        echo "                " >> ${SETTE_DIR}/output.sette
329}
330
331set_xio_using_server () {
332        minargcount=2
333        if [ ${#} -lt ${minargcount} ]
334        then
335                echo "not enough arguments for set_xio_using_server"
336                echo "${usage2}"
337                exit 1
338        fi
339        if [ $2 != "true" ] && [ $2 != "false" ]
340        then
341                echo "unrecognised argument for set_xio_using_server"
342                echo "${usage2}"
343                echo $2
344                exit 1
345        fi
346        unset minargcount
347        if [  ! -f ${SETTE_DIR}/output.sette ] ; then
348                touch ${SETTE_DIR}/output.sette
349        fi
350
351        echo "executing script : set_xio_using_server $@" >> ${SETTE_DIR}/output.sette
352        echo "################" >> ${SETTE_DIR}/output.sette
353
354        VAR_NAME=$( grep "^.*<.*variable id.*=.*using_server.*=.*bool" ${EXE_DIR}/$1 | sed -e "s% *\!.*%%" )
355        if [ ${#VAR_NAME} -eq 0 ]
356        then
357                echo "doing \"set_xio_using_server $@\". "
358                echo "xml_tag: "variable id=using_server" with variable: bool is empty"
359                echo "confirm that an appropriate variable id is in \"${EXE_DIR}/$1\" "
360                echo "exit"
361                echo "error in executing script : set_xio_using_server $@" >> ${SETTE_DIR}/output.sette
362                echo "....." >> ${SETTE_DIR}/output.sette
363                exit 1
364        fi
365        if [ $2 == "false" ]
366        then
367           sed -e "/using_server/s:true:false:" ${EXE_DIR}/$1 > ${EXE_DIR}/$1.tmp
368           export USING_MPMD=no
369        else
370           sed -e "/using_server/s:false:true:" ${EXE_DIR}/$1 > ${EXE_DIR}/$1.tmp
371           export USING_MPMD=yes
372        fi
373        mv ${EXE_DIR}/$1.tmp ${EXE_DIR}/$1
374
375        echo "finished script : set_xio_using_server $@" >> ${SETTE_DIR}/output.sette
376        echo "++++++++++++++++" >> ${SETTE_DIR}/output.sette
377        echo "                " >> ${SETTE_DIR}/output.sette
378}
379
380set_xio_buffer_size () {
381        minargcount=2
382        if [ ${#} -lt ${minargcount} ]
383        then
384                echo "not enough arguments for set_xio_buffer_size"
385                echo "${usage4}"
386                exit 1
387        fi
388        unset minargcount
389        if [  ! -f ${SETTE_DIR}/output.sette ] ; then
390                touch ${SETTE_DIR}/output.sette
391        fi
392
393        echo "executing script : set_xio_buffer_size $@" >> ${SETTE_DIR}/output.sette
394        echo "################" >> ${SETTE_DIR}/output.sette
395
396        VAR_NAME=$( grep "^.*<.*variable id.*=.*buffer_size.*=.*integer" ${EXE_DIR}/$1 | sed -e "s% *\!.*%%" )
397        if [ ${#VAR_NAME} -eq 0 ]
398        then
399                echo "doing \"set_xio_buffer_size $@\". "
400                echo "xml_tag: "variable id=buffer_size" with variable: integer is empty"
401                echo "confirm that an appropriate variable id is in \"${EXE_DIR}/$1\" "
402                echo "exit"
403                echo "error in executing script : set_xio_buffer_size $@" >> ${SETTE_DIR}/output.sette
404                echo "....." >> ${SETTE_DIR}/output.sette
405                exit 1
406        fi
407        sed -e "/buffer_size/s:>.*<:>$2<:" ${EXE_DIR}/$1 > ${EXE_DIR}/$1.tmp
408        mv ${EXE_DIR}/$1.tmp ${EXE_DIR}/$1
409
410        echo "finished script : set_xio_buffer_size $@" >> ${SETTE_DIR}/output.sette
411        echo "++++++++++++++++" >> ${SETTE_DIR}/output.sette
412        echo "                " >> ${SETTE_DIR}/output.sette
413}
414
415set_xio_field_defs () {
416        minargcount=1
417        if [ ${#} -lt ${minargcount} ]
418        then
419                echo "not enough arguments for set_xio_field_defs"
420                echo "${usage5}"
421                exit 1
422        fi
423        unset minargcount
424        if [  ! -f ${SETTE_DIR}/output.sette ] ; then
425                touch ${SETTE_DIR}/output.sette
426        fi
427
428        echo "executing script : set_xio_field_defs $@" >> ${SETTE_DIR}/output.sette
429        echo "################" >> ${SETTE_DIR}/output.sette
430
431
432        [ -f ${EXE_DIR}/field_def_nemo-oce.xml ] || sed -i '/field_def_nemo-oce/d' $1
433        [ -f ${EXE_DIR}/field_def_nemo-ice.xml ] || sed -i '/field_def_nemo-ice/d' $1
434        [ -f ${EXE_DIR}/field_def_nemo-pisces.xml ] || sed -i '/field_def_nemo-pisces/d' $1
435
436        echo "finished script : set_xio_field_defs $@" >> ${SETTE_DIR}/output.sette
437        echo "++++++++++++++++" >> ${SETTE_DIR}/output.sette
438        echo "                " >> ${SETTE_DIR}/output.sette
439}
Note: See TracBrowser for help on using the repository browser.