source: dynamico_lmdz/aquaplanet/CMIP5a/RUN_AQUAPLANET_DYNAMICO_LMDZ5/prepare.sh @ 4067

Last change on this file since 4067 was 4067, checked in by dubos, 7 years ago

CMIP5a scripts : create aquaplanet or betaclim experiment

  • Property svn:executable set to *
File size: 5.6 KB
Line 
1#!/bin/bash
2
3#---------------------- Arguments ------------------
4
5function fullpath() {
6    mkdir -p $(dirname "$1")
7    echo "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")"
8}
9
10function readargs_ce0l() {
11    MYDIR=$(fullpath $2)
12    MYSTORE=$(fullpath $3)
13    ANNEEREF=$4
14    mkdir -p $MYDIR
15    mkdir -p $MYSTORE
16    ln -sf $MYSTORE $MYDIR/store
17    echo "ce0l : MYDIR=$MYDIR MYSTORE=$MYSTORE"
18}
19
20function readargs_first() {
21    STORE0=$(fullpath $2)
22    MYDIR=$(fullpath $3)
23    MYSTORE=$(fullpath $4)
24    ANNEEREF=$5
25    mkdir -p $MYDIR
26    mkdir -p $MYSTORE
27    ln -sf $STORE0 $MYDIR/store0
28    ln -sf $MYSTORE $MYDIR/store
29}
30
31function readargs_next() {
32    STORE0=$(fullpath $2)
33    STOREPREV=$(fullpath $3)
34    MYDIR=$(fullpath $4)
35    MYSTORE=$(fullpath $5)
36    ANNEEREF=$6
37    mkdir -p $MYDIR
38    mkdir -p $MYSTORE
39    ln -sf $STORE0 $MYDIR/store0
40    ln -sf $STOREPREV $MYDIR/store_prev
41    ln -sf $MYSTORE $MYDIR/store
42}
43
44function check_env()
45{
46    if [ "$ARCH" == "" ] ; then
47        echo 'You must define environment variables ARCH and ESM_ROOT'
48        exit 1
49    fi
50    if [ "$ESM_ROOT" == "" ] ; then
51        echo 'You must define environment variables ARCH and ESM_ROOT'
52        exit 1
53    fi
54    XIOS_SERVER="${ESM_ROOT}/XIOS/bin/xios_server.exe"
55    if [ ! -f "${XIOS_SERVER}" ]; then
56        echo "${XIOS_SERVER} not found, check that ESM_ROOT=$ESM_ROOT points to the correct location"
57    fi
58   
59}
60
61#---------------- Keyword substitution -------------
62
63function def() {
64    echo "s/$1/$2/g"
65}
66
67function sed_ce0l() {
68    def USING_SERVER false
69    def CE0L yes
70    def READ_START no
71    def IFLAG_PHYS $IFLAG_PHYS0
72    def ETAT0 $ETAT0
73}
74
75function sed_first() {
76    def USING_SERVER true
77    def CE0L no
78    def READ_START yes
79    def IFLAG_PHYS 1
80    def ETAT0 $ETAT0
81}
82
83function sed_next() {
84    def USING_SERVER true
85    def CE0L no
86    def READ_START yes
87    def IFLAG_PHYS 1
88    def ETAT0 start_file
89}
90
91function sed_all() {
92    def READ_CLIMOZ $READ_CLIMOZ
93    def KEY_VEGET $VEGET
94    def SOLARLONG0 $SOLARLONG0
95    def ANNEEREF $ANNEEREF
96}
97
98#------------ Batch jobs : machine-independent prologues and epilogues  --------------
99
100function prologue_all() {
101cat <<EOF
102cd ${MYDIR}
103rm -rf gcm.log *.nc xios_*.err xios_*.out gcm.log logs
104ln -s ../FILES_LMDZ/*.nc .
105
106cat <<END  > killme.sh
107#!/bin/bash
108ccc_mdel \${BRIDGE_MSUB_JOBID}
109END
110chmod a+x killme.sh
111
112ulimit -s unlimited
113
114EOF
115cat $ESM_ROOT/ICOSA_LMDZ/arch.env
116}
117
118function prologue_first() {
119cat <<EOF
120ln -s store0/limit.nc store0/climoz_LMDZ.nc store0/startphy.nc .
121EOF
122}
123
124function prologue_next() {
125cat <<EOF
126ln -s store0/limit.nc store0/climoz_LMDZ.nc .
127ln -s store_prev/restartphy.nc startphy.nc
128ln -s store_prev/restart.nc start.nc
129EOF
130}
131
132function epilogue_ce0l(){
133    cat <<EOF
134# save useful files
135mv limit.nc startphy.nc climoz_LMDZ.nc store/
136EOF
137}
138
139function epilogue_first(){
140    cat <<EOF
141# save useful files
142mv restartphy.nc restart.nc store/
143EOF
144}
145
146function epilogue_next(){
147    cat <<EOF
148# save useful files
149mv restartphy.nc restart.nc store/
150EOF
151}
152
153function epilogue_all() {
154    cat <<EOF
155mkdir logs
156cp *.def *.xml job.sh logs/
157mv apbp.nc Ai.nc *.err *.out gcm.log logs/
158tar czf logs.tgz logs
159mv hist*.nc logs.tgz store/
160# cleanup input files
161rm -f *.nc
162EOF
163}
164
165#------------ Batch jobs : machine-dependent main script : X64_CURIE  --------------
166
167function batch_X64_CURIE_ce0l() {
168cat <<EOF
169#!/bin/bash
170## Request name
171#MSUB -r ${EXPERIMENT}_ce0l_mpi
172#MSUB -q standard
173#MSUB -A gen7548
174#MSUB -x
175## Number of tasks (=MPI processes) to use
176#MSUB -n $NB_MPI_CE0L
177## Elapsed time limit in seconds
178#MSUB -T 600
179## Quality of Service required (long [3 days], normal [1 day], test [30 min])
180#MSUB -Q normal
181
182$( prologue_all )
183date > gcm.log
184export OMP_NUM_THREADS=1
185ccc_mprun $ICOSA_LMDZ >> gcm.log
186date >> gcm.log
187$( epilogue_ce0l )
188$( epilogue_all )
189EOF
190}
191
192function batch_X64_CURIE_first() {
193batch_X64_CURIE first
194}
195
196function batch_X64_CURIE_next() {
197batch_X64_CURIE next
198}
199
200function batch_X64_CURIE() { # $1 = first or next
201NB_MPI_TOTAL=$(( $NB_MPI_DYNAMICO + $NB_MPI_XIOS ))
202cat <<EOF
203#!/bin/bash
204## Request name
205#MSUB -r ${EXPERIMENT}_$1_mpi
206#MSUB -q standard
207#MSUB -A gen7548
208#MSUB -x
209## Number of tasks (=MPI processes) to use
210#MSUB -n $NB_MPI_TOTAL
211## Elapsed time limit in seconds
212#MSUB -T $JOB_WALLTIME
213## Quality of Service required (long [3 days], normal [1 day], test [30 min])
214#MSUB -Q normal
215
216$( prologue_all )
217$( prologue_$1 )
218export OMP_NUM_THREADS=1
219ccc_mprun -f mpmd.conf
220$( epilogue_$1 )
221$( epilogue_all )
222EOF
223
224cat <<EOF > $MYDIR/mpmd.conf
225$NB_MPI_DYNAMICO ./gcm.sh
226$NB_MPI_XIOS $XIOS_SERVER
227EOF
228
229cat <<EOF > $MYDIR/gcm.sh
230#!/bin/bash
231ME=\${BRIDGE_MPRUN_RANKID}
232GCM=\$(printf 'dynamico.%04d' \$ME)
233date > \${GCM}.out
234$ICOSA_LMDZ >> \${GCM}.out 2>\${GCM}.err
235date >> \${GCM}.out
236EOF
237chmod a+x $MYDIR/gcm.sh
238}
239
240#--------------------- Main --------------------
241
242echo
243echo
244echo "Your command : $0 $*"
245echo "Working directory : $PWD"
246
247NB_MPI_DYNAMICO=160
248NB_MPI_XIOS=16
249NB_MPI_CE0L=16
250source ./config.sh
251
252check_env || exit 1
253
254XIOS_SERVER=$(fullpath "$ESM_ROOT/XIOS/bin/xios_server.exe")
255ICOSA_LMDZ=$(fullpath "$ESM_ROOT/ICOSA_LMDZ/bin/icosa_lmdz.exe")
256
257TYPE=$1
258readargs_$TYPE $*
259
260# avoid destroying xml and def files in case of mistake
261chmod a-w *.def *.xml
262
263MYSED=$(mktemp)
264sed_$TYPE > $MYSED
265sed_all >> $MYSED
266#cat $MYSED
267for FILE in *.def *.xml ; do
268    sed -f $MYSED $FILE > $MYDIR/$FILE
269done
270rm -f $MYSED
271
272chmod u+w *.def *.xml
273
274cd $MYDIR
275batch_${ARCH}_${TYPE} > job.sh
276
277#ls -l $MYDIR
278grep using_server iodef.xml
279for KEY in create_etat0_limit read_start etat0 anneeref iflag_phys read_climoz VEGET solarlong0 ; do
280    grep "\b$KEY\b" *.def | grep -v '#' # match whole words : \b means 'word boundary'
281done
Note: See TracBrowser for help on using the repository browser.