source: trunk/NEMOGCM/SETTE/all_functions.sh @ 3532

Last change on this file since 3532 was 3294, checked in by rblod, 9 years ago

Merge of 3.4beta into the trunk

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 7.2 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 enought 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 "control 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# function to tidy up after each test and populate the NEMO_VALIDATION store
132post_test_tidyup () {
133#
134# requires the following variables defined and exported from the calling script:
135#  SETTE_DIR
136#  INPUT_DIR
137#  EXE_DIR
138#  CONFIG_DIR
139#  NEMO_VALIDATION_DIR
140#  NEW_CONF
141#  CMP_NAM
142#  TEST_NAME
143echo "SETTE directory is : ${SETTE_DIR}"
144echo "INPUT directory is : ${INPUT_DIR}"
145echo "EXECUTION directory is : ${EXE_DIR}"
146echo "CONFIG directory is : ${CONFIG_DIR}"
147echo "VALIDATION directory is : ${NEMO_VALIDATION_DIR}"
148echo "NEW CONFIGURATION is : ${NEW_CONF}"
149echo "COMPILER is : ${CMP_NAM}"
150echo "TEST is : ${TEST_NAME}"
151################################################################
152# SMALL DEBUG
153    if [ ! -r ${EXE_DIR}/time.step ]
154        then
155        echo "file time.step does not exist"   >> ${SETTE_DIR}/output.sette
156        echo "some problems during execution of model"  >> ${SETTE_DIR}/output.sette
157        exit 1
158    else
159        echo "file time.step exists"  >> ${SETTE_DIR}/output.sette
160        echo "ok model run"   >> ${SETTE_DIR}/output.sette
161    fi
162################################################################
163
164################################################################
165# Creation of NEMO_VALIDATION tree
166    export LANG=en_US
167    cd ${CONFIG_DIR}
168    cd ../
169    REVISION_NB=`svn info | grep -i "Revision:" | sed -e "s/ //" | cut -d ":" -f 2`
170    if [ ${#REVISION_NB} -eq 0 ]
171    then
172      echo "some problems with svn info command"
173      echo "some problems with svn info command" >> ${SETTE_DIR}/output.sette
174      REVISION_NB=`date +%Y%m%d`
175      echo "put in ${REVISION_NB} date"
176      echo "put in ${REVISION_NB} date" >> ${SETTE_DIR}/output.sette
177    else
178    echo "value of revision number of NEMOGCM: ${REVISION_NB}"
179    fi
180    cd ${NEMO_VALIDATION_DIR}
181    `mkdir -p ${NEMO_VALIDATION_DIR}/W${NEW_CONF}/${CMP_NAM}/${REVISION_NB}/${TEST_NAME}`
182    NEMO_VALID=${NEMO_VALIDATION_DIR}/W${NEW_CONF}/${CMP_NAM}/${REVISION_NB}/${TEST_NAME}
183    if [ -d ${NEMO_VALID} ] ; then
184   echo "created ${NEMO_VALID} directory"   >> ${SETTE_DIR}/output.sette
185    else
186   echo "problems in creating ${NEMO_VALID} directory"   >> ${SETTE_DIR}/output.sette
187   echo "EXIT,"
188   exit 1
189    fi
190    # Save output & debug files in NEMO_VALIDATION tree
191    echo "saving ocean & ice output, solver.stat, tracer.stat files ...." >> ${SETTE_DIR}/output.sette
192    echo "            " >> ${SETTE_DIR}/output.sette
193    [ -f ${EXE_DIR}/*ocean.output ] && cp ${EXE_DIR}/*ocean.output ${NEMO_VALID}/.
194    [ -f ${EXE_DIR}/*solver.stat ] && cp ${EXE_DIR}/*solver.stat ${NEMO_VALID}/.
195    [ -f ${EXE_DIR}/*tracer.stat ] && cp ${EXE_DIR}/*tracer.stat ${NEMO_VALID}/.
196    if [ -n "$(ls ${NEMO_VALID}/*solver*)" ] ; then
197   echo "moved solver.stat in ${NEMO_VALID} directory"  >> ${SETTE_DIR}/output.sette
198   echo "moved solver.stat in ${NEMO_VALID} directory" 
199    else
200   echo "problem in looking for solver.stat file in ${NEMO_VALID} directory"  >> ${SETTE_DIR}/output.sette
201   echo "solver.stat IS NOT in ${NEMO_VALID} directory" 
202    fi
203    if [ -n "$(ls ${NEMO_VALID}/*ocean.output*)" ] ; then
204   echo "moved ocean.output in ${NEMO_VALID} directory"  >> ${SETTE_DIR}/output.sette
205   echo "moved ocean.output in ${NEMO_VALID} directory" 
206    else
207   echo "problem in looking for ocean.output file in ${NEMO_VALID} directory"  >> ${SETTE_DIR}/output.sette
208   echo "ocean.output IS NOT in ${NEMO_VALID} directory" 
209    fi
210    if [ -n "$(ls ${NEMO_VALID}/*tracer.stat*)" ] ; then
211        echo "moved tracer.stat in ${NEMO_VALID} directory"  >> ${SETTE_DIR}/output.sette
212        echo "moved tracer.stat in ${NEMO_VALID} directory"
213    else
214        echo "problem in looking for tracer.stat file in ${NEMO_VALID} directory"  >> ${SETTE_DIR}/output.sette
215        echo "tracer.stat IS NOT in ${NEMO_VALID} directory"
216    fi
217}
Note: See TracBrowser for help on using the repository browser.