1 | #!/bin/bash |
---|
2 | #set -v |
---|
3 | |
---|
4 | #--script to check water conservation in the IPSL coupled model |
---|
5 | #--author: Olivier Boucher |
---|
6 | #--30/11/2016 |
---|
7 | #--updated 10/05/2019 |
---|
8 | |
---|
9 | #--only work for NEMO 1 degree ! mods needed for NEMO025 |
---|
10 | |
---|
11 | #--direxp: directory of experiment up to experiment type |
---|
12 | #--exp: name of experiment |
---|
13 | #--yearbeg: first year of budget analysis (skip first year of experiment because of issues with some diagnostics) |
---|
14 | #--yearend: last year of budget analysis |
---|
15 | #--yearinc: time resolution (in year) of output files in OUTPUT |
---|
16 | #--for a good precision consider at least a period of 50 or 100 years |
---|
17 | |
---|
18 | direxp="/ccc/store/cont003/gencmip6/p86maf/IGCM_OUT/IPSLCM6/DEVT/pdControl/" |
---|
19 | exp="CM6014-pd-split-D-01" |
---|
20 | yearbeg=1910 |
---|
21 | yearend=1949 |
---|
22 | yearinc=10 |
---|
23 | |
---|
24 | #--set maketimeseries to true to force rewriting temporary files |
---|
25 | #maketimeseries=false |
---|
26 | maketimeseries=true |
---|
27 | |
---|
28 | host=`echo $HOSTNAME |cut -c 1-3` |
---|
29 | |
---|
30 | if [ $host == 'ada' ]; then |
---|
31 | #--IDRIS |
---|
32 | #--module load cdo |
---|
33 | module unload cdo |
---|
34 | module load cdo/1.6.5 |
---|
35 | module load netcdf |
---|
36 | #--output directory where to store the temporary files needed for the analysis |
---|
37 | dirout=$WORKDIR |
---|
38 | |
---|
39 | elif [ $host == 'ire' ]; then |
---|
40 | #--TGCC |
---|
41 | #--assume cdo is loaded |
---|
42 | #--output directory where to store the temporary files needed for the analysis |
---|
43 | dirout=$CCCWORKDIR |
---|
44 | |
---|
45 | else |
---|
46 | echo 'Machine not supported' |
---|
47 | exit |
---|
48 | |
---|
49 | fi |
---|
50 | |
---|
51 | #--name of output file |
---|
52 | fileout='waterbudget_'${exp}'_'${yearbeg}'_'${yearend}'.out' |
---|
53 | echo Output will be redirected to $fileout |
---|
54 | rm -f ${fileout} |
---|
55 | |
---|
56 | echo 'Dealing with ' $direxp/$exp > ${fileout} |
---|
57 | echo >> ${fileout} |
---|
58 | |
---|
59 | #--here I assume there are 360 or 365 days per year on average |
---|
60 | #--a better script would diagnose the number of days from the netcdf files |
---|
61 | nbdayinyr=365 |
---|
62 | nbmthinyr=12 |
---|
63 | |
---|
64 | #--model output directories |
---|
65 | dir_atm_day=${direxp}${exp}"/ATM/Output/DA/" |
---|
66 | dir_atm_mth=${direxp}${exp}"/ATM/Output/MO/" |
---|
67 | dir_oce_day=${direxp}${exp}"/OCE/Output/DA/" |
---|
68 | dir_oce_mth=${direxp}${exp}"/OCE/Output/MO/" |
---|
69 | dir_ice_day=${direxp}${exp}"/ICE/Output/DA/" |
---|
70 | dir_ice_mth=${direxp}${exp}"/ICE/Output/MO/" |
---|
71 | dir_srf_day=${direxp}${exp}"/SRF/Output/DA/" |
---|
72 | dir_srf_mth=${direxp}${exp}"/SRF/Output/MO/" |
---|
73 | |
---|
74 | echo 'The analysis relies on files from the following model output directories' >> ${fileout} |
---|
75 | echo $dir_atm_day >> ${fileout} |
---|
76 | echo $dir_atm_mth >> ${fileout} |
---|
77 | echo $dir_oce_day >> ${fileout} |
---|
78 | echo $dir_oce_mth >> ${fileout} |
---|
79 | echo $dir_ice_day >> ${fileout} |
---|
80 | echo $dir_ice_mth >> ${fileout} |
---|
81 | echo $dir_srf_day >> ${fileout} |
---|
82 | echo $dir_srf_mth >> ${fileout} |
---|
83 | |
---|
84 | #--number of years for the budget analysis |
---|
85 | nbyear=$((${yearend}-${yearbeg}+1)) |
---|
86 | |
---|
87 | #--water density (kg/m3) ORCHIDEE |
---|
88 | rho_liq=1000.0 |
---|
89 | #--ice density (kg/m3) in LIM3 |
---|
90 | rho_ice=917.0 |
---|
91 | #--snow density (kg/m3) in LIM3 |
---|
92 | rho_sno=330.0 |
---|
93 | #--ocean water density (kg/m3) in NEMO |
---|
94 | rho_oce=1027. |
---|
95 | #--average ratio of salty water to fresh water |
---|
96 | fresh2salt=1.035 |
---|
97 | #--conversion from /day to /s |
---|
98 | day2sec=86400. |
---|
99 | #--approximated conversion factor from m sea to Sv |
---|
100 | ssh2sv=`python -c "print 4.*3.14159*6370000.*6370000.*0.7/1.e6"` |
---|
101 | |
---|
102 | #--temporary output files |
---|
103 | fileoceout=dq_oce_${exp}_extracted_${yearbeg}_${yearend}_short.nc |
---|
104 | fileatmout=dq_atm_${exp}_extracted_${yearbeg}_${yearend}_short.nc |
---|
105 | filesrfout=dq_srf_${exp}_extracted_${yearbeg}_${yearend}_short.nc |
---|
106 | |
---|
107 | #---PREPARE ATMOS FILE |
---|
108 | if [ ${maketimeseries} = true ] || [ ! -e ${dirout}/${fileatmout} ] ; then |
---|
109 | #--delete all yearly files that may be there from a previous execution of the script |
---|
110 | rm -f ${dirout}/${fileatmout} ${dirout}/dq_atm_${exp}_extracted_????.nc |
---|
111 | #--loop on years |
---|
112 | for year1 in $(seq $yearbeg $yearinc $yearend) |
---|
113 | do |
---|
114 | year2=$((year1+yearinc-1)) |
---|
115 | file_atm=$dir_atm_mth$exp'_'$year1'0101_'$year2'123?_1M_histmth.nc' |
---|
116 | #--this diags may not be in the time series so I extract them |
---|
117 | #--some are not needed though |
---|
118 | echo cdo -L yearmonmean -selname,aire,pourc_lic,wevap_ter,wevap_oce,wevap_lic,wevap_sic,wsnow_lic,wsnow_sic,wsnow_oce,wsnow_ter,wrain_lic,wrain_sic,wrain_ter,wrain_oce,wbilo_ter,wbilo_oce,wbilo_lic,wbilo_sic,evap,precip,snow,msnow,runofflic ${file_atm} ${dirout}/dq_atm_${exp}_extracted_${year1}.nc |
---|
119 | cdo -L yearmonmean -selname,aire,pourc_lic,wevap_ter,wevap_oce,wevap_lic,wevap_sic,wsnow_lic,wsnow_sic,wsnow_oce,wsnow_ter,wrain_lic,wrain_sic,wrain_ter,wrain_oce,wbilo_ter,wbilo_oce,wbilo_lic,wbilo_sic,evap,precip,snow,runofflic ${file_atm} ${dirout}/dq_atm_${exp}_extracted_${year1}.nc |
---|
120 | done |
---|
121 | cdo -L mergetime ${dirout}/dq_atm_${exp}_extracted_????.nc ${dirout}/${fileatmout} |
---|
122 | rm -f ${dirout}/dq_atm_${exp}_extracted_????.nc |
---|
123 | fi |
---|
124 | |
---|
125 | #---PREPARE OCE FILE |
---|
126 | if [ ${maketimeseries} = true ] || [ ! -e ${dirout}/${fileoceout} ] ; then |
---|
127 | #--delete all yearly files that may be there from a previous execution of the script |
---|
128 | rm -f ${dirout}/${fileoceout} ${dirout}/dq_oce_${exp}_extracted_????.nc |
---|
129 | #--loop on years |
---|
130 | for year1 in $(seq $yearbeg $yearinc $yearend) |
---|
131 | do |
---|
132 | year2=$((year1+yearinc-1)) |
---|
133 | file_oce=$dir_oce_mth$exp'_'$year1'0101_'$year2'123?_1M_grid_T.nc' |
---|
134 | #--this diags may not be in the time series so I extract them |
---|
135 | cdo -L yearmonmean -selname,emp_oce,emp_ice,friver,calving,iceshelf,iceberg ${file_oce} ${dirout}/dq_oce_${exp}_extracted_${year1}.nc |
---|
136 | done |
---|
137 | cdo -L mergetime ${dirout}/dq_oce_${exp}_extracted_????.nc ${dirout}/${fileoceout} |
---|
138 | rm -f ${dirout}/dq_oce_${exp}_extracted_????.nc |
---|
139 | fi |
---|
140 | |
---|
141 | #---PREPARE SURFACE FILE |
---|
142 | if [ ${maketimeseries} = true ] || [ ! -e ${dirout}/${filesrfout} ] ; then |
---|
143 | #--delete all yearly files that may be there from a previous execution of the script |
---|
144 | rm -f ${dirout}/${filesrfout} ${dirout}/dq_srf_${exp}_extracted_????.nc |
---|
145 | rm -f ${dirout}/dq0_srf_${exp}_extracted_????.nc ${dirout}/dq_contfrac_${exp}_extracted_????.nc |
---|
146 | #--loop on years |
---|
147 | for year1 in $(seq $yearbeg $yearinc $yearend) |
---|
148 | do |
---|
149 | year2=$((year1+yearinc-1)) |
---|
150 | file_srf=$dir_srf_mth$exp'_'$year1'0101_'$year2'123?_1M_sechiba_history.nc' |
---|
151 | #--this diags may not be in the time series so I extract them |
---|
152 | rm -f ${dirout}/contfrac.nc ${dirout}/maxveget.nc ${dirout}/summaxveget.nc |
---|
153 | cdo -L selname,Contfrac ${file_srf} ${dirout}/contfrac.nc |
---|
154 | cdo -L selname,maxvegetfrac ${file_srf} ${dirout}/maxveget.nc |
---|
155 | cdo -L vertsum ${dirout}/maxveget.nc ${dirout}/summaxveget.nc |
---|
156 | cdo -L yearmonmean ${dirout}/summaxveget.nc ${dirout}/summaxvegetmean.nc |
---|
157 | cdo -L yearmonmean -selname,Areas,evap,evapnu,evapflo,inter,transpir,riverflow,coastalflow,rain,snowf,subli,snow,vegetfrac,DelSoilMoist_daily,DelIntercept_daily,DelSWE_daily,delstreamr_daily,delfastr_daily,delslowr_daily,delfloodr_daily,delpondr_daily,dellakevol_daily ${file_srf} ${dirout}/dq0_srf_${exp}_extracted_${year1}.nc |
---|
158 | cdo -L merge ${dirout}/summaxvegetmean.nc ${dirout}/contfrac.nc ${dirout}/dq0_srf_${exp}_extracted_${year1}.nc ${dirout}/dq_srf_${exp}_extracted_${year1}.nc |
---|
159 | done |
---|
160 | cdo -L mergetime ${dirout}/dq_srf_${exp}_extracted_????.nc ${dirout}/${filesrfout} |
---|
161 | rm -f ${dirout}/dq0_srf_${exp}_extracted_????.nc ${dirout}/dq_srf_${exp}_extracted_????.nc |
---|
162 | rm -f ${dirout}/contfrac.nc ${dirout}/maxveget.nc ${dirout}/summaxveget.nc |
---|
163 | fi |
---|
164 | |
---|
165 | #--------------------------------------------------------------------------------- |
---|
166 | echo >> ${fileout} |
---|
167 | echo 'NOTE all numbers are in Sv (1 Sv = 10^6 m3/s) of freshwater' >> ${fileout} |
---|
168 | echo 'NOTE 0.001 Sv = 8.8 mm sea level rise per century' >> ${fileout} |
---|
169 | echo >> ${fileout} |
---|
170 | echo 'We are dealing with years from' $yearbeg 'to' $yearend ', or' $nbyear 'years'>> ${fileout} |
---|
171 | if [ $nbyear -lt 30 ] ; then |
---|
172 | echo 'WARNING: at least 30 years are needed for a good accuracy because of some approximations made' >> ${fileout} |
---|
173 | else |
---|
174 | echo 'This is good, the longer the more acurate because of some approximations made' >> ${fileout} |
---|
175 | fi |
---|
176 | echo >> ${fileout} |
---|
177 | echo 'TER=land OCE=ocean SIC=sea-ice LIC=land ice' >> ${fileout} |
---|
178 | echo >> ${fileout} |
---|
179 | # |
---|
180 | #--using daily data when possible, otherwise monthly |
---|
181 | file_atm_daybeg=$dir_atm_day$exp'_'$yearbeg'0101_????123?_1D_histday.nc' |
---|
182 | file_atm_dayend=$dir_atm_day$exp'_????0101_'$yearend'123?_1D_histday.nc' |
---|
183 | file_atm_mthbeg=$dir_atm_mth$exp'_'$yearbeg'0101_????123?_1M_histmth.nc' |
---|
184 | file_atm_mthend=$dir_atm_mth$exp'_????0101_'$yearend'123?_1M_histmth.nc' |
---|
185 | # |
---|
186 | file_srf_daybeg=$dir_srf_day$exp'_'$yearbeg'0101_????123?_1D_sechiba_history.nc' |
---|
187 | file_srf_dayend=$dir_srf_day$exp'_????0101_'$yearend'123?_1D_sechiba_history.nc' |
---|
188 | file_srf_mthbeg=$dir_srf_mth$exp'_'$yearbeg'0101_????123?_1M_sechiba_history.nc' |
---|
189 | file_srf_mthend=$dir_srf_mth$exp'_????0101_'$yearend'123?_1M_sechiba_history.nc' |
---|
190 | # |
---|
191 | file_oce_daybeg=$dir_oce_day$exp'_'$yearbeg'0101_????123?_1D_scalar.nc' |
---|
192 | file_oce_dayend=$dir_oce_day$exp'_????0101_'$yearend'123?_1D_scalar.nc' |
---|
193 | file_oce_mthbeg=$dir_oce_mth$exp'_'$yearbeg'0101_????123?_1M_scalar.nc' |
---|
194 | file_oce_mthend=$dir_oce_mth$exp'_????0101_'$yearend'123?_1M_scalar.nc' |
---|
195 | # |
---|
196 | file_ice_daybeg=$dir_ice_day$exp'_'$yearbeg'0101_????123?_1D_icemod.nc' |
---|
197 | file_ice_dayend=$dir_ice_day$exp'_????0101_'$yearend'123?_1D_icemod.nc' |
---|
198 | file_ice_mthbeg=$dir_ice_mth$exp'_'$yearbeg'0101_????123?_1M_icemod.nc' |
---|
199 | file_ice_mthend=$dir_ice_mth$exp'_????0101_'$yearend'123?_1M_icemod.nc' |
---|
200 | # |
---|
201 | #--------------------------------------------------------------------------------- |
---|
202 | echo '------------------------------------------------------------------------------------' >> ${fileout} |
---|
203 | echo '--NEMO change in stores (for the records)' >> ${fileout} |
---|
204 | #--note that the total number of days of the run should be diagnosed rather than assumed |
---|
205 | #--here the result is in Sv |
---|
206 | # |
---|
207 | #--change in ocean volume in freshwater equivalent |
---|
208 | if [ -e ${file_oce_daybeg} ]; then |
---|
209 | maxtimestep=`ncdump -h ${file_oce_dayend} | grep currently | grep -o -E '[0-9]+'` |
---|
210 | OCE_vol_daybeg=`cdo -L outputf,%12.10g,10 -seltimestep,1 -selvar,scvoltot ${file_oce_daybeg}` |
---|
211 | OCE_vol_dayend=`cdo -L outputf,%12.10g,10 -seltimestep,${maxtimestep} -selvar,scvoltot ${file_oce_dayend}` |
---|
212 | echo 'OCE vol beg =' ${OCE_vol_daybeg} >> ${fileout} |
---|
213 | echo 'OCE vol end =' ${OCE_vol_dayend} >> ${fileout} |
---|
214 | dOCE_vol=`python -c "print (${OCE_vol_dayend}-${OCE_vol_daybeg})/${nbyear}/${nbdayinyr}/${day2sec}/1.e6"` |
---|
215 | else |
---|
216 | maxtimestep=`ncdump -h ${file_oce_mthend} | grep currently | grep -o -E '[0-9]+'` |
---|
217 | OCE_vol_mthbeg=`cdo -L outputf,%12.10g,10 -seltimestep,1 -selvar,scvoltot ${file_oce_mthbeg}` |
---|
218 | OCE_vol_mthend=`cdo -L outputf,%12.10g,10 -seltimestep,${maxtimestep} -selvar,scvoltot ${file_oce_mthend}` |
---|
219 | echo 'OCE vol beg =' ${OCE_vol_mthbeg} >> ${fileout} |
---|
220 | echo 'OCE vol end =' ${OCE_vol_mthend} >> ${fileout} |
---|
221 | dOCE_vol=`python -c "print (${OCE_vol_mthend}-${OCE_vol_mthbeg})/${nbyear}/${nbdayinyr}/${day2sec}/1.e6"` |
---|
222 | fi |
---|
223 | echo 'These estimates of d OCE (converted to Sv) are approximate' >> ${fileout} |
---|
224 | echo 'd OCE vol (Sv) =' ${dOCE_vol} >> ${fileout} |
---|
225 | #-- |
---|
226 | #--computing sea-ice and snow-on-sea-ice volume |
---|
227 | #--it would be better to compute from daily files but for now only monthly files available |
---|
228 | #--here we get a volume of ice (m3 of ice) by multiplying depth with surface |
---|
229 | if [ -e ${file_ice_daybeg} ]; then |
---|
230 | echo >> ${fileout} |
---|
231 | else |
---|
232 | maxtimestep=`ncdump -h ${file_ice_mthend} | grep currently | grep -o -E '[0-9]+'` |
---|
233 | SIC_volice_mthbeg=`cdo -L outputf,%12.10g,10 -fldsum -mul -seltimestep,1 -selvar,sivolu ${file_ice_mthbeg} -gridarea ${file_ice_mthbeg}` |
---|
234 | SIC_volice_mthend=`cdo -L outputf,%12.10g,10 -fldsum -mul -seltimestep,${maxtimestep} -selvar,sivolu ${file_ice_mthend} -gridarea ${file_ice_mthend}` |
---|
235 | #--converting to freswater volume |
---|
236 | #--note that the total number of days of the run should be diagnosed rather than assumed |
---|
237 | dSIC_volice=`python -c "print ${rho_ice}/${rho_liq}*(${SIC_volice_mthend}-${SIC_volice_mthbeg})/${nbyear}/${nbdayinyr}/${day2sec}/1.e6"` |
---|
238 | #--same for snow on sea-ice (m3 on snow) |
---|
239 | SIC_volsno_mthbeg=`cdo -L outputf,%12.10g,10 -fldsum -mul -seltimestep,1 -selvar,snvolu ${file_ice_mthbeg} -gridarea ${file_ice_mthbeg}` |
---|
240 | SIC_volsno_mthend=`cdo -L outputf,%12.10g,10 -fldsum -mul -seltimestep,${maxtimestep} -selvar,snvolu ${file_ice_mthend} -gridarea ${file_ice_mthend}` |
---|
241 | #--converting to freswater volume |
---|
242 | #--so we get change in sea-ice and snow in Sv |
---|
243 | dSIC_volsno=`python -c "print ${rho_sno}/${rho_liq}*(${SIC_volsno_mthend}-${SIC_volsno_mthbeg})/${nbyear}/${nbdayinyr}/${day2sec}/1.e6"` |
---|
244 | fi |
---|
245 | echo 'd SIC ice (Sv) =' ${dSIC_volice} >> ${fileout} |
---|
246 | echo 'd SIC snow (Sv) =' ${dSIC_volsno} >> ${fileout} |
---|
247 | echo '------------------------------------------------------------------------------------' >> ${fileout} |
---|
248 | echo '--NEMO fluxes (for the records)' >> ${fileout} |
---|
249 | # |
---|
250 | file=$dirout'/'$fileoceout |
---|
251 | echo EMP_OCE cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -selindexbox,2,361,1,331 -mul -timavg -selname,emp_oce ${file} -gridarea ${file} |
---|
252 | EMP_OCE=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -selindexbox,2,361,1,331 -mul -timavg -selname,emp_oce ${file} -gridarea ${file}` |
---|
253 | EMP_SIC=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -selindexbox,2,361,1,331 -mul -timavg -selname,emp_ice ${file} -gridarea ${file}` |
---|
254 | ICEBERG=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -selindexbox,2,361,1,331 -mul -timavg -selname,iceberg ${file} -gridarea ${file}` |
---|
255 | ICESHELF=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -selindexbox,2,361,1,331 -mul -timavg -selname,iceshelf ${file} -gridarea ${file}` |
---|
256 | CALVING=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -selindexbox,2,361,1,331 -mul -timavg -selname,calving ${file} -gridarea ${file}` |
---|
257 | FRIVER=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -selindexbox,2,361,1,331 -mul -timavg -selname,friver ${file} -gridarea ${file}` |
---|
258 | echo 'EMP_OCE=' $EMP_OCE >> ${fileout} |
---|
259 | echo 'EMP_OCE + CALVING=' `python -c "print $EMP_OCE + $CALVING"` >> ${fileout} |
---|
260 | echo 'EMP_SIC=' $EMP_SIC >> ${fileout} |
---|
261 | echo 'EMP_OCE + EMP_SIC + CALVING =' `python -c "print $EMP_OCE + $EMP_SIC + $CALVING"` >> ${fileout} |
---|
262 | echo 'ICEBERG =' $ICEBERG >> ${fileout} |
---|
263 | echo 'ICESHELF=' $ICESHELF >> ${fileout} |
---|
264 | echo 'CALVING =' $CALVING >> ${fileout} |
---|
265 | echo 'FRIVER =' $FRIVER >> ${fileout} |
---|
266 | echo '------------------------------------------------------------------------------------' >> ${fileout} |
---|
267 | CREATED_OCESIC=`python -c "print ${dOCE_vol}+${dSIC_volice}+${dSIC_volsno}+${EMP_OCE}+${EMP_SIC}-${FRIVER}-${ICEBERG}-${ICESHELF}"` |
---|
268 | echo 'WATER CREATED BY OCE+SIC is computed as' >> ${fileout} |
---|
269 | echo 'dOCE_vol + dSIC_volice + dSIC_volsno + EMP_OCE + EMP_SIC - FRIVER - ICEBERG - ICESHELF' >> ${fileout} |
---|
270 | echo 'and should be as small as possible, ideally ~ 0.001 Sv over a 50 to 100 year period' >> ${fileout} |
---|
271 | echo 'WATER CREATED BY OCE+SIC=' ${CREATED_OCESIC} >> ${fileout} |
---|
272 | # |
---|
273 | echo '------------------------------------------------------------------------------------' >> ${fileout} |
---|
274 | echo '--LMDZ changes in stores (for the records)' >> ${fileout} |
---|
275 | echo 'should be less than 0.001 Sv for prw and even smaller for cloud water' >> ${fileout} |
---|
276 | #--change in precipitable water from the atmosphere daily and monthly files |
---|
277 | #--compute sum weighted by gridcell area (kg/m2) then convert to Sv |
---|
278 | if [ -e ${file_atm_daybeg} ]; then |
---|
279 | maxtimestep=`ncdump -h ${file_atm_dayend} | grep currently | grep -o -E '[0-9]+'` |
---|
280 | ATM_prw_daybeg=`cdo -L outputf,%12.10g,10 -fldsum -mul -seltimestep,1 -selvar,prw ${file_atm_daybeg} -gridarea ${file_atm_daybeg}` |
---|
281 | ATM_prw_dayend=`cdo -L outputf,%12.10g,10 -fldsum -mul -seltimestep,${maxtimestep} -selvar,prw ${file_atm_dayend} -gridarea ${file_atm_dayend}` |
---|
282 | dATM_prw=`python -c "print (${ATM_prw_dayend}-${ATM_prw_daybeg})/${nbyear}/${nbdayinyr}/${day2sec}/1.e9"` |
---|
283 | #--now same with cloud liquid water (small term) |
---|
284 | ATM_prlw_daybeg=`cdo -L outputf,%12.10g,10 -fldsum -mul -seltimestep,1 -selvar,prlw ${file_atm_daybeg} -gridarea ${file_atm_daybeg}` |
---|
285 | ATM_prlw_dayend=`cdo -L outputf,%12.10g,10 -fldsum -mul -seltimestep,${maxtimestep} -selvar,prlw ${file_atm_dayend} -gridarea ${file_atm_dayend}` |
---|
286 | dATM_prlw=`python -c "print (${ATM_prlw_dayend}-${ATM_prlw_daybeg})/${nbyear}/${nbdayinyr}/${day2sec}/1.e9"` |
---|
287 | #--now same with cloud ice water (small term) |
---|
288 | ATM_prsw_daybeg=`cdo -L outputf,%12.10g,10 -fldsum -mul -seltimestep,1 -selvar,prsw ${file_atm_daybeg} -gridarea ${file_atm_daybeg}` |
---|
289 | ATM_prsw_dayend=`cdo -L outputf,%12.10g,10 -fldsum -mul -seltimestep,${maxtimestep} -selvar,prsw ${file_atm_dayend} -gridarea ${file_atm_dayend}` |
---|
290 | dATM_prsw=`python -c "print (${ATM_prsw_dayend}-${ATM_prsw_daybeg})/${nbyear}/${nbdayinyr}/${day2sec}/1.e9"` |
---|
291 | else |
---|
292 | maxtimestep=`ncdump -h ${file_atm_mthend} | grep currently | grep -o -E '[0-9]+'` |
---|
293 | ATM_prw_mthbeg=`cdo -L outputf,%12.10g,10 -fldsum -mul -seltimestep,1 -selvar,prw ${file_atm_mthbeg} -gridarea ${file_atm_mthbeg}` |
---|
294 | ATM_prw_mthend=`cdo -L outputf,%12.10g,10 -fldsum -mul -seltimestep,${maxtimestep} -selvar,prw ${file_atm_mthend} -gridarea ${file_atm_mthend}` |
---|
295 | dATM_prw=`python -c "print (${ATM_prw_mthend}-${ATM_prw_mthbeg})/${nbyear}/${nbdayinyr}/${day2sec}/1.e9"` |
---|
296 | # |
---|
297 | ATM_prlw_mthbeg=`cdo -L outputf,%12.10g,10 -fldsum -mul -seltimestep,1 -selvar,prlw ${file_atm_mthbeg} -gridarea ${file_atm_mthbeg}` |
---|
298 | ATM_prlw_mthend=`cdo -L outputf,%12.10g,10 -fldsum -mul -seltimestep,${maxtimestep} -selvar,prlw ${file_atm_mthend} -gridarea ${file_atm_mthend}` |
---|
299 | dATM_prlw=`python -c "print (${ATM_prlw_mthend}-${ATM_prlw_mthbeg})/${nbyear}/${nbdayinyr}/${day2sec}/1.e9"` |
---|
300 | # |
---|
301 | ATM_prsw_mthbeg=`cdo -L outputf,%12.10g,10 -fldsum -mul -seltimestep,1 -selvar,prsw ${file_atm_mthbeg} -gridarea ${file_atm_mthbeg}` |
---|
302 | ATM_prsw_mthend=`cdo -L outputf,%12.10g,10 -fldsum -mul -seltimestep,${maxtimestep} -selvar,prsw ${file_atm_mthend} -gridarea ${file_atm_mthend}` |
---|
303 | dATM_prsw=`python -c "print (${ATM_prsw_mthend}-${ATM_prsw_mthbeg})/${nbyear}/${nbdayinyr}/${day2sec}/1.e9"` |
---|
304 | # |
---|
305 | ATM_snowlic_mthbeg=`cdo -L outputf,%12.10g,10 -fldsum -mul -seltimestep,1 -expr,'msnow*pourc_lic/100.' ${file_atm_mthbeg} -gridarea ${file_atm_mthbeg}` |
---|
306 | ATM_snowlic_mthend=`cdo -L outputf,%12.10g,10 -fldsum -mul -seltimestep,${maxtimestep} -expr,'msnow*pourc_lic/100.' ${file_atm_mthend} -gridarea ${file_atm_mthend}` |
---|
307 | dATM_snowlic=`python -c "print (${ATM_snowlic_mthend}-${ATM_snowlic_mthbeg})/${nbyear}/${nbdayinyr}/${day2sec}/1.e9"` |
---|
308 | fi |
---|
309 | echo 'd ATM from prw (Sv) =' ${dATM_prw} >> ${fileout} |
---|
310 | echo 'd ATM from prlw (Sv) =' ${dATM_prlw} >> ${fileout} |
---|
311 | echo 'd ATM from prsw (Sv) =' ${dATM_prsw} >> ${fileout} |
---|
312 | dATM_tot=`python -c "print ${dATM_prw}+${dATM_prlw}+${dATM_prsw}"` |
---|
313 | # |
---|
314 | echo '------------------------------------------------------------------------------------' >> ${fileout} |
---|
315 | echo '--LMDZ fluxes (for the records)' >> ${fileout} |
---|
316 | #--defining atmospheric file |
---|
317 | file=${dirout}/${fileatmout} |
---|
318 | # |
---|
319 | #--atmospheric fluxes (converted to Sv) |
---|
320 | PREC=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=precip' ${file} -gridarea ${file}` |
---|
321 | RAIN_OCE=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wrain_oce' ${file} -gridarea ${file}` |
---|
322 | RAIN_SIC=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wrain_sic' ${file} -gridarea ${file}` |
---|
323 | RAIN_TER=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wrain_ter' ${file} -gridarea ${file}` |
---|
324 | RAIN_LIC=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wrain_lic' ${file} -gridarea ${file}` |
---|
325 | SNOW=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=snow' ${file} -gridarea ${file}` |
---|
326 | SNOW_OCE=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wsnow_oce' ${file} -gridarea ${file}` |
---|
327 | SNOW_SIC=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wsnow_sic' ${file} -gridarea ${file}` |
---|
328 | SNOW_TER=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wsnow_ter' ${file} -gridarea ${file}` |
---|
329 | SNOW_LIC=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wsnow_lic' ${file} -gridarea ${file}` |
---|
330 | EVAP=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=evap' ${file} -gridarea ${file}` |
---|
331 | EVAP_OCE=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wevap_oce' ${file} -gridarea ${file}` |
---|
332 | EVAP_SIC=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wevap_sic' ${file} -gridarea ${file}` |
---|
333 | EVAP_TER=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wevap_ter' ${file} -gridarea ${file}` |
---|
334 | EVAP_LIC=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wevap_lic' ${file} -gridarea ${file}` |
---|
335 | #--better to compute precip-evap then sum (rather than the other way around) |
---|
336 | PRECMINUSEVAP=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=precip-evap' ${file} -gridarea ${file}` |
---|
337 | echo 'PRECIP - EVAP should be < 0.0001 Sv' >> ${fileout} |
---|
338 | echo 'PRECIP - EVAP (Sv) =' ${PREC} '-' ${EVAP} '=' ${PRECMINUSEVAP} >> ${fileout} |
---|
339 | echo 'Next three lines are optional' >> ${fileout} |
---|
340 | echo 'Numbers come in this order OCE + SIC + TER + LIC = TOTAL' >> ${fileout} |
---|
341 | echo 'RAIN by tile and total (Sv) =' ${RAIN_OCE} '+' ${RAIN_SIC} '+' ${RAIN_TER} '+' ${RAIN_LIC} '=' \ |
---|
342 | `python -c "print ${RAIN_OCE}+${RAIN_SIC}+${RAIN_TER}+${RAIN_LIC}"` >> ${fileout} |
---|
343 | echo 'SNOW by tile and total (Sv) =' ${SNOW_OCE} '+' ${SNOW_SIC} '+' ${SNOW_TER} '+' ${SNOW_LIC} '=' \ |
---|
344 | `python -c "print ${SNOW_OCE}+${SNOW_SIC}+${SNOW_TER}+${SNOW_LIC}"` >> ${fileout} |
---|
345 | echo 'EVAP by tile and total (Sv) =' ${EVAP_OCE} '+' ${EVAP_SIC} '+' ${EVAP_TER} '+' ${EVAP_LIC} '=' \ |
---|
346 | `python -c "print ${EVAP_OCE}+${EVAP_SIC}+${EVAP_TER}+${EVAP_LIC}"` >> ${fileout} |
---|
347 | #--water budget by surface type as seen from atmosphere |
---|
348 | echo 'Net water budget (evap-precip) by land surface type in LMDz' >> ${fileout} |
---|
349 | BILO_TER=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -selvar,wbilo_ter ${file} -gridarea ${file}` |
---|
350 | echo 'BILO TER (Sv)=' $BILO_TER >> ${fileout} |
---|
351 | BILO_OCE=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -selvar,wbilo_oce ${file} -gridarea ${file}` |
---|
352 | echo 'BILO OCE (Sv)=' $BILO_OCE >> ${fileout} |
---|
353 | BILO_SIC=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -selvar,wbilo_sic ${file} -gridarea ${file}` |
---|
354 | echo 'BILO SIC (Sv)=' $BILO_SIC >> ${fileout} |
---|
355 | BILO_LIC=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -selvar,wbilo_lic ${file} -gridarea ${file}` |
---|
356 | echo 'BILO LIC (Sv)=' $BILO_LIC >> ${fileout} |
---|
357 | BILO_tot=`python -c "print $BILO_TER+$BILO_OCE+$BILO_SIC+$BILO_LIC"` >> ${fileout} |
---|
358 | echo 'The BILO tot diag below should be similar (+/-5e-6) to PRECIP-EVAP above but with opposite sign' >> ${fileout} |
---|
359 | echo 'BILO tot (Sv)=' $BILO_tot >> ${fileout} |
---|
360 | echo 'The BILO OCE+SIC diag below should be the same (within <0.001 Sv) as EMP_OCE+EMP_ICE+CALVING above ' >> ${fileout} |
---|
361 | echo 'BILO OCE+SIC (Sv)=' `python -c "print $BILO_OCE+$BILO_SIC"` >> ${fileout} |
---|
362 | #--here we add PRLW and PRSW when they exist but these are small |
---|
363 | CREATED_ATM=`python -c "print ${PRECMINUSEVAP}+${dATM_prw}+${dATM_prlw}+${dATM_prsw}"` |
---|
364 | echo '------------------------------------------------------------------------------------' >> ${fileout} |
---|
365 | echo 'Water created in LMDZ should be < 0.001 Sv' >> ${fileout} |
---|
366 | echo 'WATER_CREATED_IN_ATM (Sv)=' ${CREATED_ATM} >> ${fileout} |
---|
367 | echo '------------------------------------------------------------------------------------' >> ${fileout} |
---|
368 | # |
---|
369 | echo '--LIC change in store and fluxes' >> ${fileout} |
---|
370 | #--water going to the ocean |
---|
371 | RUNOFFLIC=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=runofflic*pourc_lic/100.' ${file} -gridarea ${file}` |
---|
372 | echo 'Atmospheric calving can be different from that reaching the ocean because there is a buffer' >> ${fileout} |
---|
373 | echo 'CALVING atm (Sv)=' $RUNOFFLIC >> ${fileout} |
---|
374 | dLIC_tot=`python -c "print -${BILO_LIC}-${RUNOFFLIC}"` |
---|
375 | echo 'd LIC (Sv) = ' ${dLIC_tot} >> ${fileout} |
---|
376 | #--by construction |
---|
377 | CREATED_LIC=0 |
---|
378 | echo 'd LIC diagnosed from msnow (Sv) = ' ${dATM_snowlic} >> ${fileout} |
---|
379 | # |
---|
380 | #-------------------------------------------------------------------------------------------------------- |
---|
381 | #--SECHIBA budgets |
---|
382 | file=${dirout}/${filesrfout} |
---|
383 | echo '------------------------------------------------------------------------------------' >> ${fileout} |
---|
384 | echo '--SECHIBA change in stores' >> ${fileout} |
---|
385 | #--changes in reservoirs - from tendencies |
---|
386 | dSoilHum_in_Sv=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=(maxvegetfrac*DelSoilMoist_daily)*Contfrac' ${file} -gridarea ${file}` |
---|
387 | dInterce_in_Sv=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=DelIntercept_daily*Contfrac' ${file} -gridarea ${file}` |
---|
388 | dSWE_in_Sv=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=DelSWE_daily*Contfrac' ${file} -gridarea ${file}` |
---|
389 | dStream_in_Sv=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delstreamr_daily*Contfrac' ${file} -gridarea ${file}` |
---|
390 | dFastR_in_Sv=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delfastr_daily*Contfrac' ${file} -gridarea ${file}` |
---|
391 | dSlowR_in_Sv=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delslowr_daily*Contfrac' ${file} -gridarea ${file}` |
---|
392 | dFlood_in_Sv=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delfloodr_daily*Contfrac' ${file} -gridarea ${file}` |
---|
393 | dPond_in_Sv=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delpondr_daily*Contfrac' ${file} -gridarea ${file}` |
---|
394 | dLake_in_Sv=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=dellakevol_daily*Contfrac' ${file} -gridarea ${file}` |
---|
395 | echo 'dSTOCK Soil Hum (Sv) =' $dSoilHum_in_Sv >> ${fileout} |
---|
396 | echo 'dSTOCK Intercept (Sv) =' $dInterce_in_Sv >> ${fileout} |
---|
397 | echo 'dSTOCK Snow (Sv) =' $dSWE_in_Sv >> ${fileout} |
---|
398 | echo 'dSTOCK Stream (Sv) =' $dStream_in_Sv >> ${fileout} |
---|
399 | echo 'dSTOCK FastR (Sv) =' $dFastR_in_Sv >> ${fileout} |
---|
400 | echo 'dSTOCK SlowR (Sv) =' $dSlowR_in_Sv >> ${fileout} |
---|
401 | echo 'dSTOCK Lake (Sv) =' $dLake_in_Sv >> ${fileout} |
---|
402 | echo 'dSTOCK Pond (Sv) =' $dPond_in_Sv >> ${fileout} |
---|
403 | echo 'dSTOCK Flood (Sv) =' $dFlood_in_Sv >> ${fileout} |
---|
404 | dSRF_tot=`python -c "print $dSoilHum_in_Sv+$dInterce_in_Sv+$dSWE_in_Sv+$dStream_in_Sv+$dFastR_in_Sv+$dSlowR_in_Sv+$dLake_in_Sv+$dPond_in_Sv+$dFlood_in_Sv"` |
---|
405 | echo 'dSTOCK Total (Sv) =' ${dSRF_tot} >> ${fileout} |
---|
406 | # |
---|
407 | echo '------------------------------------------------------------------------------------' >> ${fileout} |
---|
408 | echo '--SECHIBA fluxes' >> ${fileout} |
---|
409 | EVAP_SRF=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -selvar,evap ${file} -gridarea ${file}` |
---|
410 | echo 'EVAP SRF (Sv)=' ${EVAP_SRF} >> ${fileout} |
---|
411 | EVAPNU_SRF=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -selvar,evapnu ${file} -gridarea ${file}` |
---|
412 | EVAPFL_SRF=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -selvar,evapflo ${file} -gridarea ${file}` |
---|
413 | SUBLIM_SRF=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -selvar,subli ${file} -gridarea ${file}` |
---|
414 | TRANSP_SRF=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -vertsum -selvar,transpir ${file} -gridarea ${file}` |
---|
415 | INTERC_SRF=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -vertsum -selvar,inter ${file} -gridarea ${file}` |
---|
416 | echo 'This diagnoses how different is EVAP from the sum of known terms in SECHIBA' >> ${fileout} |
---|
417 | echo 'The terms are evap bare soil, evap flooding plains, sublimation, transpiration, interception' >> ${fileout} |
---|
418 | echo 'The difference with EVAP SRF should be small <0.0001 Sv' >> ${fileout} |
---|
419 | echo 'EVAP TERMS SRF=' $EVAPNU_SRF '+' $EVAPFL_SRF '+' $SUBLIM_SRF '+' $TRANSP_SRF '+' $INTERC_SRF >> ${fileout} |
---|
420 | echo 'EVAP TOTAL SRF=' `python -c "print ${EVAPNU_SRF}+${EVAPFL_SRF}+${SUBLIM_SRF}+${TRANSP_SRF}+${INTERC_SRF}"` >> ${fileout} |
---|
421 | # |
---|
422 | echo 'RAINFALL SRF=' `cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=rain*Contfrac' ${file} -gridarea ${file}` >> ${fileout} |
---|
423 | echo 'SNOWFALL SRF=' `cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=snowf*Contfrac' ${file} -gridarea ${file}` >> ${fileout} |
---|
424 | IN_SRF=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=(rain+snowf-evap)*Contfrac' ${file} -gridarea ${file}` |
---|
425 | echo 'The SECH NET SRF (precip - evap over land) should be the same as BILO TER above but opposite sign' >> ${fileout} |
---|
426 | echo 'SECH NET SRF=' ${IN_SRF} >> ${fileout} |
---|
427 | # |
---|
428 | #--flow to ocean (Sv) |
---|
429 | FLOW=`cdo -L outputf,%12.8g,8 -divc,1.e6 -fldsum -timavg -expr,'toto=coastalflow+riverflow' ${file}` |
---|
430 | echo 'FLOW to the ocean should the same (<0.0001 Sv) as FRIVER above' >> ${fileout} |
---|
431 | echo 'FLOW to ocean (Sv)=' ${FLOW} >> ${fileout} |
---|
432 | echo '------------------------------------------------------------------------------------' >> ${fileout} |
---|
433 | #--budget of SRF alltogether |
---|
434 | CREATED_SRF=`python -c "print ${FLOW}-${IN_SRF}+${dSRF_tot}"` |
---|
435 | echo 'Created water by ORCHIDEE should be < 0.0001 Sv' >> ${fileout} |
---|
436 | echo 'WATER CREATED BY ORCHIDEE=' ${FLOW} '-' ${IN_SRF} '+' ${dSRF_tot} '=' ${CREATED_SRF} >> ${fileout} |
---|
437 | # |
---|
438 | echo '------------------------------------------------------------------------------------' >> ${fileout} |
---|
439 | echo 'SUMMARY' >> ${fileout} |
---|
440 | echo 'd ATM (Sv) =' ${dATM_tot} >> ${fileout} |
---|
441 | echo 'd LIC (Sv) =' ${dLIC_tot} >> ${fileout} |
---|
442 | echo 'd SRF (Sv) =' ${dSRF_tot} >> ${fileout} |
---|
443 | echo 'd OCE (Sv) =' ${dOCE_vol} >> ${fileout} |
---|
444 | echo 'd SIC ice (Sv) =' ${dSIC_volice} >> ${fileout} |
---|
445 | echo 'd SIC snow (Sv) =' ${dSIC_volsno} >> ${fileout} |
---|
446 | CREATED_TOT1=`python -c "print ${dATM_tot}+${dLIC_tot}+${dSRF_tot}+${dOCE_vol}+${dSIC_volice}+${dSIC_volsno}"` |
---|
447 | CREATED_TOT2=`python -c "print ${CREATED_OCESIC}+${CREATED_SRF}+${CREATED_ATM}+${CREATED_LIC}"` |
---|
448 | echo 'Two different diagnostics of created water rate in the coupled model' >> ${fileout} |
---|
449 | echo 'should be < 0.003 Sv in the current state of affairs' >> ${fileout} |
---|
450 | echo 'WATER CREATED TOTAL (Sv) =' ${CREATED_TOT1} >> ${fileout} |
---|
451 | echo 'WATER CREATED TOTAL (Sv) =' ${CREATED_TOT2} >> ${fileout} |
---|
452 | echo '------------------------------------------------------------------------------------' >> ${fileout} |
---|