source: branches/2017/dev_r8183_ICEMODEL/NEMOGCM/SETTE/all_functions.sh @ 8517

Last change on this file since 8517 was 8226, checked in by clem, 4 years ago

merge with dev_r8127_AGRIF_LIM3_GHOST@r8189 and dev_r8126_ROBUST08_no_ghost@r8196

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