Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
set -xv
date=${1}
day_end=$( date -d "${date:4:2}/1 + 1 month - 1 day" +"%d" )
date_end=${date:0:6}${day_end}
ym=${date:0:6}
day_nb=$(( ($(date -d "${date_end}H00 + 1 day" +%s) - $(date -d "${ym}01H00" +"%s") )/(60*60*24) ))
dir_out="/ec/res4/scratch/ar0s/ERA5/GRIB_N320/${ym}"; mkdir -p ${dir_out}
dir_req=$(dirname ${2}:-".")
file_req=$(basename ${2%*.req*})
req_type=${file_req/mars_} ; req_type=${req_type%%_*}
file_out="${req_type%%_*}_ERA5_L*_GLO_TLAUTO_IGNONE_GN320_ana01h_${date}.grib"
if [ ! -s ${dir_out}/${file_out} ]; then
# EDIT MARS REQ
if [ -f ${dir_req}/${file_req}.req.base ]; then
sed -e "s~date_req~${date}~g; s~dir_out~${dir_out}~g" < ${dir_req}/${file_req}.req.base > ${dir_req}/JOBS/${file_out}.req
else
echo "MARS REQUEST NOT FOUND !"
exit 1
fi
# SUBMIT MARS REQUEST
while [ $(squeue -u $USER -h -t pending,running -r | wc -l) -eq 100 ]; do echo "sleeping..."; sleep 10; done
if [ ${date} -eq ${date_end} ]; then echo "waiting..."; w="--wait"; fi
sbatch ${w} --job-name=mars_${req_type}_${date} <<EOF
#!/bin/bash
#SBATCH --job-name=marsreq
#SBATCH --output=JOBS/%x-%j.out
#SBATCH --qos=nf
#SBATCH --time=00:30:00
set +xv
mars ${dir_req}/JOBS/${file_out}.req
exit 0
EOF
if [ -n "${w}" ]; then
file_nb=$( eval "ls ${dir_out}/${file_out/${date}/${ym}??} 2>/dev/null" | wc -l )
if [ ${day_nb} -eq ${file_nb} ]; then echo "OK"; exit 0; else echo "ERROR"; exit 1; fi
fi
fi