source: TOOLS/WATER_BUDGET/waterbudget.sh @ 4605

Last change on this file since 4605 was 4427, checked in by oboucher, 5 years ago

water budget script for IPSL-CM6A-LR

  • Property svn:executable set to *
File size: 29.0 KB
Line 
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
18direxp="/ccc/store/cont003/gencmip6/p86maf/IGCM_OUT/IPSLCM6/DEVT/pdControl/"
19exp="CM6014-pd-split-D-01"
20yearbeg=1910
21yearend=1949
22yearinc=10
23
24#--set maketimeseries to true to force rewriting temporary files
25#maketimeseries=false
26maketimeseries=true
27
28host=`echo $HOSTNAME |cut -c 1-3`
29
30if [ $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
39elif [ $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
45else
46  echo 'Machine not supported'
47  exit
48
49fi
50
51#--name of output file
52fileout='waterbudget_'${exp}'_'${yearbeg}'_'${yearend}'.out'
53echo Output will be redirected to $fileout
54rm -f ${fileout}
55
56echo 'Dealing with ' $direxp/$exp > ${fileout}
57echo >> ${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
61nbdayinyr=365
62nbmthinyr=12
63
64#--model output directories
65dir_atm_day=${direxp}${exp}"/ATM/Output/DA/"
66dir_atm_mth=${direxp}${exp}"/ATM/Output/MO/"
67dir_oce_day=${direxp}${exp}"/OCE/Output/DA/"
68dir_oce_mth=${direxp}${exp}"/OCE/Output/MO/"
69dir_ice_day=${direxp}${exp}"/ICE/Output/DA/"
70dir_ice_mth=${direxp}${exp}"/ICE/Output/MO/"
71dir_srf_day=${direxp}${exp}"/SRF/Output/DA/"
72dir_srf_mth=${direxp}${exp}"/SRF/Output/MO/"
73
74echo 'The analysis relies on files from the following model output directories' >> ${fileout}
75echo $dir_atm_day >> ${fileout}
76echo $dir_atm_mth >> ${fileout}
77echo $dir_oce_day >> ${fileout}
78echo $dir_oce_mth >> ${fileout}
79echo $dir_ice_day >> ${fileout}
80echo $dir_ice_mth >> ${fileout}
81echo $dir_srf_day >> ${fileout}
82echo $dir_srf_mth >> ${fileout}
83
84#--number of years for the budget analysis
85nbyear=$((${yearend}-${yearbeg}+1))
86
87#--water density (kg/m3) ORCHIDEE
88rho_liq=1000.0
89#--ice density (kg/m3) in LIM3
90rho_ice=917.0
91#--snow density (kg/m3) in LIM3
92rho_sno=330.0
93#--ocean water density (kg/m3) in NEMO
94rho_oce=1027.
95#--average ratio of salty water to fresh water
96fresh2salt=1.035
97#--conversion from /day to /s
98day2sec=86400.
99#--approximated conversion factor from m sea to Sv
100ssh2sv=`python -c "print 4.*3.14159*6370000.*6370000.*0.7/1.e6"`
101
102#--temporary output files
103fileoceout=dq_oce_${exp}_extracted_${yearbeg}_${yearend}_short.nc
104fileatmout=dq_atm_${exp}_extracted_${yearbeg}_${yearend}_short.nc
105filesrfout=dq_srf_${exp}_extracted_${yearbeg}_${yearend}_short.nc
106
107#---PREPARE ATMOS FILE
108if [ ${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
123fi
124
125#---PREPARE OCE FILE
126if [ ${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
139fi
140
141#---PREPARE SURFACE FILE
142if [ ${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
163fi
164
165#---------------------------------------------------------------------------------
166echo >> ${fileout}
167echo 'NOTE all numbers are in Sv (1 Sv = 10^6 m3/s) of freshwater' >> ${fileout}
168echo 'NOTE 0.001 Sv = 8.8 mm sea level rise per century' >> ${fileout}
169echo >> ${fileout}
170echo 'We are dealing with years from' $yearbeg 'to' $yearend ', or' $nbyear 'years'>> ${fileout}
171if [ $nbyear -lt 30 ] ; then
172  echo 'WARNING: at least 30 years are needed for a good accuracy because of some approximations made' >> ${fileout}
173else
174  echo 'This is good, the longer the more acurate because of some approximations made' >> ${fileout}
175fi
176echo >> ${fileout}
177echo 'TER=land OCE=ocean SIC=sea-ice LIC=land ice' >> ${fileout}
178echo >> ${fileout}
179#
180#--using daily data when possible, otherwise monthly
181file_atm_daybeg=$dir_atm_day$exp'_'$yearbeg'0101_????123?_1D_histday.nc'
182file_atm_dayend=$dir_atm_day$exp'_????0101_'$yearend'123?_1D_histday.nc'
183file_atm_mthbeg=$dir_atm_mth$exp'_'$yearbeg'0101_????123?_1M_histmth.nc'
184file_atm_mthend=$dir_atm_mth$exp'_????0101_'$yearend'123?_1M_histmth.nc'
185#
186file_srf_daybeg=$dir_srf_day$exp'_'$yearbeg'0101_????123?_1D_sechiba_history.nc'
187file_srf_dayend=$dir_srf_day$exp'_????0101_'$yearend'123?_1D_sechiba_history.nc'
188file_srf_mthbeg=$dir_srf_mth$exp'_'$yearbeg'0101_????123?_1M_sechiba_history.nc'
189file_srf_mthend=$dir_srf_mth$exp'_????0101_'$yearend'123?_1M_sechiba_history.nc'
190#
191file_oce_daybeg=$dir_oce_day$exp'_'$yearbeg'0101_????123?_1D_scalar.nc'
192file_oce_dayend=$dir_oce_day$exp'_????0101_'$yearend'123?_1D_scalar.nc'
193file_oce_mthbeg=$dir_oce_mth$exp'_'$yearbeg'0101_????123?_1M_scalar.nc'
194file_oce_mthend=$dir_oce_mth$exp'_????0101_'$yearend'123?_1M_scalar.nc'
195#
196file_ice_daybeg=$dir_ice_day$exp'_'$yearbeg'0101_????123?_1D_icemod.nc'
197file_ice_dayend=$dir_ice_day$exp'_????0101_'$yearend'123?_1D_icemod.nc'
198file_ice_mthbeg=$dir_ice_mth$exp'_'$yearbeg'0101_????123?_1M_icemod.nc'
199file_ice_mthend=$dir_ice_mth$exp'_????0101_'$yearend'123?_1M_icemod.nc'
200#
201#---------------------------------------------------------------------------------
202echo '------------------------------------------------------------------------------------' >> ${fileout}
203echo '--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
208if [ -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"`
215else
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"`
222fi
223echo 'These estimates of d OCE (converted to Sv) are approximate'  >> ${fileout}
224echo '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
229if [ -e ${file_ice_daybeg} ]; then
230  echo  >> ${fileout}
231else
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"`
244fi
245echo 'd SIC ice (Sv)  =' ${dSIC_volice} >> ${fileout}
246echo 'd SIC snow (Sv) =' ${dSIC_volsno} >> ${fileout}
247echo '------------------------------------------------------------------------------------' >> ${fileout}
248echo '--NEMO fluxes (for the records)'  >> ${fileout}
249#
250file=$dirout'/'$fileoceout
251echo 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}
252EMP_OCE=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -selindexbox,2,361,1,331 -mul -timavg -selname,emp_oce ${file} -gridarea ${file}`
253EMP_SIC=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -selindexbox,2,361,1,331 -mul -timavg -selname,emp_ice ${file} -gridarea ${file}`
254ICEBERG=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -selindexbox,2,361,1,331 -mul -timavg -selname,iceberg ${file} -gridarea ${file}`
255ICESHELF=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -selindexbox,2,361,1,331 -mul -timavg -selname,iceshelf ${file} -gridarea ${file}`
256CALVING=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -selindexbox,2,361,1,331 -mul -timavg -selname,calving ${file} -gridarea ${file}`
257FRIVER=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -selindexbox,2,361,1,331 -mul -timavg -selname,friver ${file} -gridarea ${file}`
258echo 'EMP_OCE=' $EMP_OCE >> ${fileout}
259echo 'EMP_OCE + CALVING=' `python -c "print $EMP_OCE + $CALVING"` >> ${fileout}
260echo 'EMP_SIC=' $EMP_SIC >> ${fileout}
261echo 'EMP_OCE + EMP_SIC + CALVING =' `python -c "print $EMP_OCE + $EMP_SIC + $CALVING"` >> ${fileout}
262echo 'ICEBERG =' $ICEBERG >> ${fileout}
263echo 'ICESHELF=' $ICESHELF >> ${fileout}
264echo 'CALVING =' $CALVING >> ${fileout}
265echo 'FRIVER  =' $FRIVER >> ${fileout}
266echo '------------------------------------------------------------------------------------' >> ${fileout}
267CREATED_OCESIC=`python -c "print ${dOCE_vol}+${dSIC_volice}+${dSIC_volsno}+${EMP_OCE}+${EMP_SIC}-${FRIVER}-${ICEBERG}-${ICESHELF}"`
268echo 'WATER CREATED BY OCE+SIC is computed as' >> ${fileout}
269echo 'dOCE_vol + dSIC_volice + dSIC_volsno + EMP_OCE + EMP_SIC - FRIVER - ICEBERG - ICESHELF' >> ${fileout}
270echo 'and should be as small as possible, ideally ~ 0.001 Sv over a 50 to 100 year period'  >> ${fileout}
271echo 'WATER CREATED BY OCE+SIC=' ${CREATED_OCESIC} >> ${fileout}
272#
273echo '------------------------------------------------------------------------------------' >> ${fileout}
274echo '--LMDZ changes in stores (for the records)' >> ${fileout}
275echo '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
278if [ -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"`
291else
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"`
308fi
309echo 'd ATM from prw  (Sv) =' ${dATM_prw} >> ${fileout}
310echo 'd ATM from prlw (Sv) =' ${dATM_prlw} >> ${fileout}
311echo 'd ATM from prsw (Sv) =' ${dATM_prsw} >> ${fileout}
312dATM_tot=`python -c "print ${dATM_prw}+${dATM_prlw}+${dATM_prsw}"`
313#
314echo '------------------------------------------------------------------------------------' >> ${fileout}
315echo '--LMDZ fluxes (for the records)' >> ${fileout}
316#--defining atmospheric file
317file=${dirout}/${fileatmout}
318#
319#--atmospheric fluxes (converted to Sv)
320PREC=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=precip' ${file} -gridarea ${file}`
321RAIN_OCE=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wrain_oce' ${file} -gridarea ${file}`
322RAIN_SIC=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wrain_sic' ${file} -gridarea ${file}`
323RAIN_TER=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wrain_ter' ${file} -gridarea ${file}`
324RAIN_LIC=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wrain_lic' ${file} -gridarea ${file}`
325SNOW=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=snow' ${file} -gridarea ${file}`
326SNOW_OCE=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wsnow_oce' ${file} -gridarea ${file}`
327SNOW_SIC=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wsnow_sic' ${file} -gridarea ${file}`
328SNOW_TER=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wsnow_ter' ${file} -gridarea ${file}`
329SNOW_LIC=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wsnow_lic' ${file} -gridarea ${file}`
330EVAP=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=evap' ${file} -gridarea ${file}`
331EVAP_OCE=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wevap_oce' ${file} -gridarea ${file}`
332EVAP_SIC=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wevap_sic' ${file} -gridarea ${file}`
333EVAP_TER=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=wevap_ter' ${file} -gridarea ${file}`
334EVAP_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)
336PRECMINUSEVAP=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=precip-evap' ${file} -gridarea ${file}`
337echo 'PRECIP - EVAP should be < 0.0001 Sv'  >> ${fileout}
338echo 'PRECIP - EVAP (Sv) =' ${PREC} '-' ${EVAP} '=' ${PRECMINUSEVAP} >> ${fileout}
339echo 'Next three lines are optional' >> ${fileout} 
340echo 'Numbers come in this order OCE + SIC + TER + LIC = TOTAL' >> ${fileout}
341echo '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}
343echo '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}
345echo '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
348echo 'Net water budget (evap-precip) by land surface type in LMDz' >> ${fileout}
349BILO_TER=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -selvar,wbilo_ter ${file} -gridarea ${file}`
350echo 'BILO TER (Sv)=' $BILO_TER >> ${fileout}
351BILO_OCE=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -selvar,wbilo_oce ${file} -gridarea ${file}`
352echo 'BILO OCE (Sv)=' $BILO_OCE >> ${fileout}
353BILO_SIC=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -selvar,wbilo_sic ${file} -gridarea ${file}`
354echo 'BILO SIC (Sv)=' $BILO_SIC >> ${fileout}
355BILO_LIC=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -selvar,wbilo_lic ${file} -gridarea ${file}`
356echo 'BILO LIC (Sv)=' $BILO_LIC >> ${fileout}
357BILO_tot=`python -c "print $BILO_TER+$BILO_OCE+$BILO_SIC+$BILO_LIC"` >> ${fileout}
358echo 'The BILO tot diag below should be similar (+/-5e-6) to PRECIP-EVAP above but with opposite sign' >> ${fileout}
359echo 'BILO tot (Sv)=' $BILO_tot >> ${fileout}
360echo 'The BILO OCE+SIC diag below should be the same (within <0.001 Sv) as EMP_OCE+EMP_ICE+CALVING above ' >> ${fileout}
361echo '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
363CREATED_ATM=`python -c "print ${PRECMINUSEVAP}+${dATM_prw}+${dATM_prlw}+${dATM_prsw}"`
364echo '------------------------------------------------------------------------------------' >> ${fileout}
365echo 'Water created in LMDZ should be < 0.001 Sv'  >> ${fileout}
366echo 'WATER_CREATED_IN_ATM (Sv)=' ${CREATED_ATM} >> ${fileout}
367echo '------------------------------------------------------------------------------------' >> ${fileout}
368#
369echo '--LIC change in store and fluxes' >> ${fileout}
370#--water going to the ocean
371RUNOFFLIC=`cdo -L outputf,%12.8g,8 -divc,1.e9 -fldsum -mul -timavg -expr,'toto=runofflic*pourc_lic/100.' ${file} -gridarea ${file}`
372echo 'Atmospheric calving can be different from that reaching the ocean because there is a buffer'  >> ${fileout}
373echo 'CALVING atm (Sv)=' $RUNOFFLIC >> ${fileout}
374dLIC_tot=`python -c "print -${BILO_LIC}-${RUNOFFLIC}"`
375echo 'd LIC (Sv) = ' ${dLIC_tot} >> ${fileout}
376#--by construction
377CREATED_LIC=0
378echo 'd LIC diagnosed from msnow (Sv) = ' ${dATM_snowlic} >> ${fileout}
379#
380#--------------------------------------------------------------------------------------------------------
381#--SECHIBA budgets
382file=${dirout}/${filesrfout}
383echo '------------------------------------------------------------------------------------' >> ${fileout}
384echo '--SECHIBA change in stores' >> ${fileout}
385#--changes in reservoirs - from tendencies
386dSoilHum_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}`
387dInterce_in_Sv=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=DelIntercept_daily*Contfrac' ${file} -gridarea ${file}`
388dSWE_in_Sv=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=DelSWE_daily*Contfrac' ${file} -gridarea ${file}`
389dStream_in_Sv=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delstreamr_daily*Contfrac' ${file} -gridarea ${file}`
390dFastR_in_Sv=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delfastr_daily*Contfrac' ${file} -gridarea ${file}`
391dSlowR_in_Sv=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delslowr_daily*Contfrac' ${file} -gridarea ${file}`
392dFlood_in_Sv=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delfloodr_daily*Contfrac' ${file} -gridarea ${file}`
393dPond_in_Sv=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delpondr_daily*Contfrac' ${file} -gridarea ${file}`
394dLake_in_Sv=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=dellakevol_daily*Contfrac' ${file} -gridarea ${file}`
395echo 'dSTOCK Soil Hum (Sv)  =' $dSoilHum_in_Sv >> ${fileout}
396echo 'dSTOCK Intercept (Sv) =' $dInterce_in_Sv >> ${fileout}
397echo 'dSTOCK Snow (Sv)      =' $dSWE_in_Sv >> ${fileout}
398echo 'dSTOCK Stream (Sv)    =' $dStream_in_Sv >> ${fileout}
399echo 'dSTOCK FastR (Sv)     =' $dFastR_in_Sv >> ${fileout}
400echo 'dSTOCK SlowR (Sv)     =' $dSlowR_in_Sv >> ${fileout}
401echo 'dSTOCK Lake (Sv)      =' $dLake_in_Sv >> ${fileout}
402echo 'dSTOCK Pond (Sv)      =' $dPond_in_Sv >> ${fileout}
403echo 'dSTOCK Flood (Sv)     =' $dFlood_in_Sv >> ${fileout}
404dSRF_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"`
405echo 'dSTOCK Total (Sv)     =' ${dSRF_tot} >> ${fileout}
406#
407echo '------------------------------------------------------------------------------------' >> ${fileout}
408echo '--SECHIBA fluxes' >> ${fileout}
409EVAP_SRF=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -selvar,evap ${file} -gridarea ${file}`
410echo 'EVAP SRF (Sv)=' ${EVAP_SRF} >> ${fileout}
411EVAPNU_SRF=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -selvar,evapnu ${file} -gridarea ${file}`
412EVAPFL_SRF=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -selvar,evapflo ${file} -gridarea ${file}`
413SUBLIM_SRF=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -selvar,subli ${file} -gridarea ${file}`
414TRANSP_SRF=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -vertsum -selvar,transpir ${file} -gridarea ${file}`
415INTERC_SRF=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -vertsum -selvar,inter ${file} -gridarea ${file}`
416echo 'This diagnoses how different is EVAP from the sum of known terms in SECHIBA' >> ${fileout}
417echo 'The terms are evap bare soil, evap flooding plains, sublimation, transpiration, interception' >> ${fileout}
418echo 'The difference with EVAP SRF should be small <0.0001 Sv' >> ${fileout}
419echo 'EVAP TERMS SRF=' $EVAPNU_SRF '+' $EVAPFL_SRF '+' $SUBLIM_SRF '+' $TRANSP_SRF '+' $INTERC_SRF  >> ${fileout}
420echo 'EVAP TOTAL SRF=' `python -c "print ${EVAPNU_SRF}+${EVAPFL_SRF}+${SUBLIM_SRF}+${TRANSP_SRF}+${INTERC_SRF}"` >> ${fileout}
421#
422echo 'RAINFALL SRF=' `cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=rain*Contfrac' ${file} -gridarea ${file}`  >> ${fileout}
423echo 'SNOWFALL SRF=' `cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=snowf*Contfrac' ${file} -gridarea ${file}` >> ${fileout}
424IN_SRF=`cdo -L outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=(rain+snowf-evap)*Contfrac' ${file} -gridarea ${file}` 
425echo 'The SECH NET SRF (precip - evap over land) should be the same as BILO TER above but opposite sign' >> ${fileout}
426echo 'SECH NET SRF=' ${IN_SRF} >> ${fileout}
427#
428#--flow to ocean (Sv)
429FLOW=`cdo -L outputf,%12.8g,8 -divc,1.e6 -fldsum -timavg -expr,'toto=coastalflow+riverflow' ${file}`
430echo 'FLOW to the ocean should the same (<0.0001 Sv) as FRIVER above' >> ${fileout}
431echo 'FLOW to ocean (Sv)=' ${FLOW} >> ${fileout}
432echo '------------------------------------------------------------------------------------' >> ${fileout}
433#--budget of SRF alltogether
434CREATED_SRF=`python -c "print ${FLOW}-${IN_SRF}+${dSRF_tot}"`
435echo 'Created water by ORCHIDEE should be < 0.0001 Sv' >> ${fileout}
436echo 'WATER CREATED BY ORCHIDEE=' ${FLOW} '-' ${IN_SRF} '+' ${dSRF_tot} '=' ${CREATED_SRF} >> ${fileout}
437#
438echo '------------------------------------------------------------------------------------' >> ${fileout}
439echo 'SUMMARY' >> ${fileout}
440echo 'd ATM (Sv) =' ${dATM_tot}         >> ${fileout}
441echo 'd LIC (Sv) =' ${dLIC_tot}         >> ${fileout}
442echo 'd SRF (Sv) =' ${dSRF_tot}         >> ${fileout}
443echo 'd OCE (Sv) =' ${dOCE_vol}         >> ${fileout}
444echo 'd SIC ice  (Sv) =' ${dSIC_volice} >> ${fileout}
445echo 'd SIC snow (Sv) =' ${dSIC_volsno} >> ${fileout}
446CREATED_TOT1=`python -c "print ${dATM_tot}+${dLIC_tot}+${dSRF_tot}+${dOCE_vol}+${dSIC_volice}+${dSIC_volsno}"`
447CREATED_TOT2=`python -c "print ${CREATED_OCESIC}+${CREATED_SRF}+${CREATED_ATM}+${CREATED_LIC}"`
448echo 'Two different diagnostics of created water rate in the coupled model' >> ${fileout}
449echo 'should be < 0.003 Sv in the current state of affairs' >> ${fileout}
450echo 'WATER CREATED TOTAL (Sv) =' ${CREATED_TOT1} >> ${fileout}
451echo 'WATER CREATED TOTAL (Sv) =' ${CREATED_TOT2} >> ${fileout}
452echo '------------------------------------------------------------------------------------' >> ${fileout}
Note: See TracBrowser for help on using the repository browser.