source: BOL/Scripts_ce0l/SST_SIC_ERA/mk_prepa_daily-SST-SIC_ERA.sh @ 4923

Last change on this file since 4923 was 4907, checked in by musat, 7 months ago

Script to create daily SST and SIC files from ERA5
I.Musat

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