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}/${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 | \rm tmp.jnl |
---|
102 | cat<<eof>tmp.jnl |
---|
103 | go go_sstk_stk.jnl ${yr}${mth} ${ndays} ${res} ${data} |
---|
104 | quit |
---|
105 | eof |
---|
106 | |
---|
107 | ###ferret -batch tmp.ps -script go_sstk_stk.jnl ${yr}${mth} ${ndays} ${res} ${data} |
---|
108 | ferret<tmp.jnl |
---|
109 | |
---|
110 | echo mth $mth ndays ${ndays} |
---|
111 | |
---|
112 | done |
---|
113 | |
---|
114 | #exit |
---|
115 | |
---|
116 | varnew=sst |
---|
117 | cdo cat ${varnew}_${data}.${yr}*.nc ${varnew}_daily_${data}.${yr}.nc |
---|
118 | |
---|
119 | echo |
---|
120 | echo Change dimensions and SST variable names and add the K unit. |
---|
121 | echo This are mandatory for using the SSTs/SICs files as input files to the |
---|
122 | echo create_eta0_limit.F90 main code. |
---|
123 | echo |
---|
124 | var=sst |
---|
125 | varM=SST |
---|
126 | varnew=tosbcs |
---|
127 | fin=${var}_daily_${data}.${yr}.nc |
---|
128 | fout=${varnew}_daily_${data}.${yr}.nc |
---|
129 | ncrename -v LONGITUDE,longitude -d LONGITUDE,longitude ${fin} |
---|
130 | ncrename -v LATITUDE,latitude -d LATITUDE,latitude ${fin} |
---|
131 | ncrename -v TIME,time -d TIME,time ${fin} |
---|
132 | ncrename -v ${varM},${varnew} ${fin} |
---|
133 | ncatted -a units,${varnew},a,c,"K" ${fin} |
---|
134 | mv ${fin} ${fout} |
---|
135 | |
---|
136 | echo |
---|
137 | echo Get SICs field : files named "ci" are containing the siconc or ci variable |
---|
138 | echo corresponding to sea-ice in 0-1 unit |
---|
139 | echo |
---|
140 | var=ci |
---|
141 | for mth in $MONTHS; do |
---|
142 | |
---|
143 | cp ${din}/${var}.${yr}${mth}.${suff}.${res}.nc . |
---|
144 | cdo daymean ${var}.${yr}${mth}.${suff}.${res}.nc ${var}_daily.${yr}${mth}.${res}.nc |
---|
145 | chmod u+w ${var}.${yr}${mth}.${suff}.${res}.nc |
---|
146 | \rm ${var}.${yr}${mth}.${suff}.${res}.nc |
---|
147 | |
---|
148 | done |
---|
149 | |
---|
150 | cdo cat ${var}_daily.${yr}*.${res}.nc ${var}_daily_${data}.${yr}.nc |
---|
151 | |
---|
152 | echo |
---|
153 | echo Rename siconc or ci variable as sicbcs, multiply it by 100 and change unit |
---|
154 | echo |
---|
155 | if [ $yr -ge 2008 ] && [ $yr -le 2017 ]; then |
---|
156 | varname=ci |
---|
157 | else |
---|
158 | varname=siconc |
---|
159 | fi |
---|
160 | |
---|
161 | fin=${var}_daily_${data}.${yr}.nc |
---|
162 | varnew=sicbcs |
---|
163 | mulc=100. |
---|
164 | fout=${varnew}_daily_${data}.${yr}.nc |
---|
165 | cdo mulc,$mulc ${fin} ${fout} |
---|
166 | ncrename -v ${varname},${varnew} ${fout} |
---|
167 | ncatted -a units,${varnew},o,c,"%" ${fout} |
---|
168 | |
---|
169 | \rm ci*nc sst*nc skt*nc |
---|
170 | |
---|
171 | exit |
---|