1 | #!/bin/bash |
---|
2 | |
---|
3 | echo |
---|
4 | echo This bash script gets the SSTs and SICc from |
---|
5 | echo hourly ERA5 data and prepares the input files |
---|
6 | echo containing daily values that should be used to |
---|
7 | echo create limit.nc boundary file for LMDZ. |
---|
8 | echo |
---|
9 | echo The SST field contains sstk over ocean and skt over land. |
---|
10 | echo The SIC files contain either siconc field for the |
---|
11 | echo period 1979-2007 or ci field for the 2008-2017 period. |
---|
12 | echo See below !!! |
---|
13 | echo |
---|
14 | echo This script was tested on spirit2 machine. |
---|
15 | echo |
---|
16 | echo To execute this script you need to give the year as input |
---|
17 | echo ./mk_prepa_daily-SST-SIC_ERA.sh $yr |
---|
18 | echo |
---|
19 | echo For exemple for 2020 year : |
---|
20 | echo ./mk_prepa_daily-SST-SIC_ERA.sh 2020 |
---|
21 | echo |
---|
22 | echo Ionela Musat, 12/03/2024 |
---|
23 | echo |
---|
24 | |
---|
25 | module load ferret |
---|
26 | |
---|
27 | local=`pwd` |
---|
28 | |
---|
29 | yr=$1 |
---|
30 | |
---|
31 | data=ERA5 |
---|
32 | res=GLOBAL_025 |
---|
33 | ret=hourly |
---|
34 | dtype=AN_SF |
---|
35 | suff=as1e5 |
---|
36 | |
---|
37 | echo din is the input directory containing ERA5 daily data |
---|
38 | echo for $yr year |
---|
39 | ###din=/bdd/ERA5/NETCDF/GLOBAL_025/hourly/AN_SF/${yr} |
---|
40 | din=/bdd/${data}/NETCDF/${res}/${ret}/${dtype}/${yr} |
---|
41 | |
---|
42 | MONTHS="01 02 03 04 05 06 07 08 09 10 11 12" |
---|
43 | |
---|
44 | for mth in $MONTHS; do |
---|
45 | |
---|
46 | if [ "${mth}" == "02" ]; then |
---|
47 | ### ndays=`mk_an_bissextile.sh ${yr}` |
---|
48 | |
---|
49 | echo |
---|
50 | echo Check if the year is a leap one or not |
---|
51 | echo |
---|
52 | echo A leap year is a year which is a multiple of 4, |
---|
53 | echo except for years evenly divisible by 100, but not by 400. |
---|
54 | echo |
---|
55 | let " yrs4 = ${yr} / 4" |
---|
56 | let " yrs100 = ${yr} / 100" |
---|
57 | let " yrs400 = ${yr} / 400" |
---|
58 | |
---|
59 | let "yrd4 = ${yrs4} *4 " |
---|
60 | let "yrd100 = ${yrs100} *100 " |
---|
61 | let "yrd400 = ${yrs400} *400 " |
---|
62 | |
---|
63 | ndays=28 |
---|
64 | if [ ${yr} == ${yrd400} ]; then |
---|
65 | ndays=29 |
---|
66 | elif [ ${yr} == ${yrd100} ]; then |
---|
67 | ndays=28 |
---|
68 | elif [ ${yr} == ${yrd4} ]; then |
---|
69 | ndays=29 |
---|
70 | fi |
---|
71 | |
---|
72 | if [ "${ndays}" == "29" ]; then |
---|
73 | echo $yr is a leap year |
---|
74 | else |
---|
75 | echo $yr is a noleap year |
---|
76 | fi |
---|
77 | |
---|
78 | fi |
---|
79 | |
---|
80 | case $mth in |
---|
81 | 01|03|05|07|08|10|12) ndays=31 ;; |
---|
82 | 04|06|09|11) ndays=30 ;; |
---|
83 | esac |
---|
84 | |
---|
85 | var=skt |
---|
86 | cp ${din}/${var}.${yr}${mth}.${suff}.${res}.nc . |
---|
87 | cdo daymean ${var}.${yr}${mth}.${suff}.${res}.nc ${var}_daily.${yr}${mth}.${res}.nc |
---|
88 | chmod u+w ${var}.${yr}${mth}.${suff}.${res}.nc |
---|
89 | \rm ${var}.${yr}${mth}.${suff}.${res}.nc |
---|
90 | |
---|
91 | var=sstk |
---|
92 | cp ${din}/${yr}/${var}.${yr}${mth}.${suff}.${res}.nc . |
---|
93 | cdo daymean ${var}.${yr}${mth}.${suff}.${res}.nc ${var}_daily.${yr}${mth}.${res}.nc |
---|
94 | chmod u+w ${var}.${yr}${mth}.${suff}.${res}.nc |
---|
95 | \rm ${var}.${yr}${mth}.${suff}.${res}.nc |
---|
96 | |
---|
97 | if [ -f tmp.ps ]; then |
---|
98 | \rm tmp.ps |
---|
99 | fi |
---|
100 | |
---|
101 | cat<<eof>go_sstk_stk.jnl |
---|
102 | cancel data/all |
---|
103 | cancel view |
---|
104 | |
---|
105 | use "skt_daily.$1.$3.nc" |
---|
106 | use "sstk_daily.$1.$3.nc" |
---|
107 | |
---|
108 | let sst = if sstk[d=2] then sstk[d=2] else skt[d=1] |
---|
109 | shade sst[l=1]-skt[d=1,l=1]; go land |
---|
110 | |
---|
111 | save/file=sst_$4.$1.nc sst[l=1] |
---|
112 | repeat/l=2:$2 (save/append/file=sst_$4.$1.nc sst[l=`l`]) |
---|
113 | quit |
---|
114 | |
---|
115 | eof |
---|
116 | |
---|
117 | ferret -batch tmp.ps -script go_sstk_stk.jnl ${yr}${mth} ${ndays} ${res} ${data} |
---|
118 | |
---|
119 | echo mth $mth ndays ${ndays} |
---|
120 | |
---|
121 | done |
---|
122 | |
---|
123 | varnew=sst |
---|
124 | cdo cat ${varnew}_${data}.${yr}*.nc ${varnew}_daily_${data}.${yr}.nc |
---|
125 | |
---|
126 | echo |
---|
127 | echo Change dimensions and SST variable names and add the K unit. |
---|
128 | echo This are mandatory for using the SSTs/SICs files as input files to the |
---|
129 | echo create_eta0_limit.F90 main code. |
---|
130 | echo |
---|
131 | var=sst |
---|
132 | varM=SST |
---|
133 | varnew=tosbcs |
---|
134 | fin=${var}_daily_${data}.${yr}.nc |
---|
135 | fout=${varnew}_daily_${data}.${yr}.nc |
---|
136 | ncrename -v LONGITUDE,longitude -d LONGITUDE,longitude ${fin} |
---|
137 | ncrename -v LATITUDE,latitude -d LATITUDE,latitude ${fin} |
---|
138 | ncrename -v TIME,time -d TIME,time ${fin} |
---|
139 | ncrename -v ${varM},${varnew} ${fin} |
---|
140 | ncatted -a units,${varnew},a,c,"K" ${fin} |
---|
141 | mv ${fin} ${fout} |
---|
142 | |
---|
143 | echo |
---|
144 | echo Get SICs field : files named "ci" are containing the siconc or ci variable |
---|
145 | echo corresponding to sea-ice in 0-1 unit |
---|
146 | echo |
---|
147 | var=ci |
---|
148 | for mth in $MONTHS; do |
---|
149 | |
---|
150 | cp ${din}/${var}.${yr}${mth}.${suff}.${res}.nc . |
---|
151 | cdo daymean ${var}.${yr}${mth}.${suff}.${res}.nc ${var}_daily.${yr}${mth}.${res}.nc |
---|
152 | chmod u+w ${var}.${yr}${mth}.${suff}.${res}.nc |
---|
153 | \rm ${var}.${yr}${mth}.${suff}.${res}.nc |
---|
154 | |
---|
155 | done |
---|
156 | |
---|
157 | cdo cat ${var}_daily.${yr}*.${res}.nc ${var}_daily_${data}.${yr}.nc |
---|
158 | |
---|
159 | echo |
---|
160 | echo Rename siconc or ci variable as sicbcs, multiply it by 100 and change unit |
---|
161 | echo |
---|
162 | if [ $yr -ge 2008 ] && [ $yr -le 2017 ]; then |
---|
163 | varname=ci |
---|
164 | else |
---|
165 | varname=siconc |
---|
166 | fi |
---|
167 | |
---|
168 | fin=${var}_daily_${data}.${yr}.nc |
---|
169 | varnew=sicbcs |
---|
170 | mulc=100. |
---|
171 | fout=${varnew}_daily_${data}.${yr}.nc |
---|
172 | cdo mulc,$mulc ${fin} ${fout} |
---|
173 | ncrename -v ${varname},${varnew} ${fout} |
---|
174 | ncatted -a units,${varnew},o,c,"%" ${fout} |
---|
175 | |
---|
176 | \rm ci*nc sst*nc skt*nc |
---|
177 | |
---|
178 | exit |
---|