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

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

aquaplanet scripts : minor fixes and improvements

  • Property svn:executable set to *
File size: 5.3 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 true
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
104
105symlink() { if [ -e \$1 ] ; then ln -s \$1 \$2 ; fi ; }
106
107for x in ../FILES_LMDZ/*.nc ; do ln -s \$x . ; done
108
109cat <<END  > killme.sh
110#!/bin/bash
111ccc_mdel \${BRIDGE_MSUB_JOBID}
112END
113chmod a+x killme.sh
114
115ulimit -s unlimited
116
117EOF
118cat $ESM_ROOT/ICOSA_LMDZ/arch.env
119}
120
121function prologue_ce0l() {
122echo
123}
124
125function prologue_first() {
126cat <<EOF
127symlink store0/limit.nc .
128symlink store0/climoz_LMDZ.nc .
129symlink store0/startphy.nc .
130EOF
131}
132
133function prologue_next() {
134cat <<EOF
135symlink store0/limit.nc .
136symlink store0/climoz_LMDZ.nc .
137symlink store_prev/restartphy.nc startphy.nc
138symlink store_prev/restart.nc start.nc
139EOF
140}
141
142function epilogue_ce0l(){
143    cat <<EOF
144# save useful files
145mv limit.nc startphy.nc climoz_LMDZ.nc store/
146EOF
147}
148
149function epilogue_first(){
150    cat <<EOF
151# save useful files
152mv restartphy.nc restart.nc store/
153EOF
154}
155
156function epilogue_next(){
157    cat <<EOF
158# save useful files
159mv restartphy.nc restart.nc store/
160EOF
161}
162
163function epilogue_all() {
164    cat <<EOF
165mkdir logs
166cp *.def *.xml job.sh logs/
167mv apbp.nc Ai.nc *.err *.out gcm.log logs/
168tar czf logs.tgz logs
169mv hist*.nc logs.tgz store/
170# cleanup input files
171rm -f *.nc
172EOF
173}
174
175#------------ Batch jobs : machine-dependent main script : X64_CURIE  --------------
176
177function batch_X64_CURIE_ce0l() {
178batch_X64_CURIE ce0l $WALLTIME_CE0L
179}
180
181function batch_X64_CURIE_first() {
182batch_X64_CURIE first $WALLTIME_JOB
183}
184
185function batch_X64_CURIE_next() {
186batch_X64_CURIE next $WALLTIME_JOB
187}
188
189function batch_X64_CURIE() { # $1 = first or next $2 = walltime
190NB_MPI_TOTAL=$(( $NB_MPI_DYNAMICO + $NB_MPI_XIOS ))
191cat <<EOF
192#!/bin/bash
193## Request name
194#MSUB -r ${EXPERIMENT}_$1_mpi
195#MSUB -q standard
196#MSUB -A gen7548
197#MSUB -x
198## Number of tasks (=MPI processes) to use
199#MSUB -n $NB_MPI_TOTAL
200## Elapsed time limit in seconds
201#MSUB -T $2
202## Quality of Service required (long [3 days], normal [1 day], test [30 min])
203#MSUB -Q normal
204
205$( prologue_all )
206$( prologue_$1 )
207export OMP_NUM_THREADS=1
208ccc_mprun -f mpmd.conf
209$( epilogue_$1 )
210$( epilogue_all )
211EOF
212
213cat <<EOF > $MYDIR/mpmd.conf
214$NB_MPI_DYNAMICO ./gcm.sh
215$NB_MPI_XIOS $XIOS_SERVER
216EOF
217
218cat <<EOF > $MYDIR/gcm.sh
219#!/bin/bash
220ME=\${BRIDGE_MPRUN_RANKID}
221GCM=\$(printf 'dynamico.%04d' \$ME)
222date > \${GCM}.out
223$ICOSA_LMDZ >> \${GCM}.out 2>\${GCM}.err
224date >> \${GCM}.out
225EOF
226chmod a+x $MYDIR/gcm.sh
227}
228
229#--------------------- Main --------------------
230
231echo
232echo
233echo "Your command : $0 $*"
234echo "Working directory : $PWD"
235
236NB_MPI_DYNAMICO=160
237NB_MPI_XIOS=16
238NB_MPI_CE0L=16
239source ./config.sh
240
241check_env || exit 1
242
243XIOS_SERVER=$(fullpath "$ESM_ROOT/XIOS/bin/xios_server.exe")
244ICOSA_LMDZ=$(fullpath "$ESM_ROOT/ICOSA_LMDZ/bin/icosa_lmdz.exe")
245
246TYPE=$1
247readargs_$TYPE $* || exit
248
249# avoid destroying xml and def files in case of mistake
250chmod a-w *.def *.xml
251
252MYSED=$(mktemp)
253sed_$TYPE > $MYSED
254sed_all >> $MYSED
255#cat $MYSED
256for FILE in *.def *.xml ; do
257    sed -f $MYSED $FILE > $MYDIR/$FILE
258done
259rm -f $MYSED
260
261chmod u+w *.def *.xml
262
263cd $MYDIR
264batch_${ARCH}_${TYPE} > job.sh
265
266#ls -l $MYDIR
267grep using_server iodef.xml
268for KEY in create_etat0_limit read_start etat0 anneeref iflag_phys read_climoz VEGET solarlong0 ; do
269    grep "\b$KEY\b" *.def | grep -v '#' # match whole words : \b means 'word boundary'
270done
Note: See TracBrowser for help on using the repository browser.