wndpert.sh 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. #/bin/ksh
  2. set -evx
  3. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. # This script computes daily perturbation from any NEMO forcing variable
  5. # ('u10', 'v10', 't2', 'q2', 'qsw', 'qlw', 'snow', 'precip') by picking up
  6. # randomly monthly differences between ERAinterim and DFS4.3 forcing fields
  7. # and interpolating these to a daily frequency (see more details in Guemas
  8. # et al, 2014, Climate Dynamics)
  9. #
  10. # This script chases a fly with a flame thrower because it has been written
  11. # while testing many different options. It works but it should be better
  12. # rewritten.
  13. #
  14. # History : Virginie Guemas - Initial version - 2012
  15. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  16. # Arguments
  17. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. lstvars=( 'u10' 'v10' )
  19. # Variables for which to compute and pick up random perturbations
  20. lstmbs=( 1 2 3 4 )
  21. # List of members for which to build pertubation files
  22. dfs2era='T' # Interpolation from DFS4 to ERA (T) or from ERA to DFS (F)
  23. # to build differences and perturbations
  24. patherain='/cfu/scratch/vguemas/ERAint/'
  25. # Path were to find the ERAinterim forcing files
  26. pathdfsin='/cfu/scratch/vguemas/dfs4.3/'
  27. # Path were to find the DFS4.3 forcing files
  28. year0=1979 # Initial year of the reference period to compute perturbations
  29. yearf=2006 # Last year of the reference period to compute perturbations
  30. year1=2012 # First year for which to pick and build a pertubation file
  31. year2=2014 # Last year for which to pick and build a perturbation file
  32. nstep=1460 # Number of time steps for a non-leap year : 1460 or 365
  33. raw='F' # Compute the timestep differences between raw ERA and DFS fields
  34. # If the script has already run once and the differences have
  35. # been stored, this option can be set to F for the step of picking
  36. # up random perturbations.
  37. ano='F' # Compute anomalies relative to a monthly-smoothed daily climatology
  38. # and the timestep differences between anomalies of ERA and DFS fields
  39. # raw=T needs to have run before. If the script has already run once and
  40. # the timesteps differences have been stored, this option can be set to F.
  41. reorg='F' # Reorganize the differences timestep per timestep all the years together
  42. # rather than year per year with all the timesteps. Works on anomalies
  43. # if wih is set to 'ano_' and raw differences if wih is set to '_'
  44. # Once the computation of differences and their reorganization has been
  45. # performed once (raw=T, ano=T, reorg=T), the results are stored in directories
  46. # named according to the options set and raw, ano and reorg can be set
  47. # to F for the picking up.
  48. wih='ano_' # Which types needs to be picked for the perturbations
  49. monmean='T' # Compute monthly mean differences and pickup perturbations from monthly mean
  50. # differences rather than timestep differences
  51. pickup1='T' # Pickup random perturbations for each member, variable, year, either
  52. # one per timestep or one per month
  53. pickup2='F' # Pickup 2 random perturbations and average them for each member, variable,
  54. # year, each timestep
  55. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  56. if [[ $dfs2era == T ]] ; then
  57. dif='eraint-dfs4.3'
  58. dir0='era-dfs'
  59. else
  60. dif='dfs4.3-eraint'
  61. dir0='dfs-era'
  62. fi
  63. for var in ${lstvars[@]} ; do
  64. if [[ $raw == T ]] ; then
  65. for ((year=$year0;year<=$yearf;year++)) ; do
  66. cp ${patherain}/${var}_eraint_${year}.nc ${var}_eraint_${year}.nc
  67. ncpdq -O -U ${var}_eraint_${year}.nc ${var}_eraint_${year}.nc
  68. if [[ $nstep == 1460 ]] ; then
  69. case $year in
  70. 1980|1984|1988|1992|1996|2000|2004|2008|2012|2016)
  71. ncks -O -d time,0,232 ${var}_eraint_${year}.nc ${var}_eraint_${year}_1.nc
  72. ncks -O -d time,237, ${var}_eraint_${year}.nc ${var}_eraint_${year}_2.nc
  73. ncrcat -O ${var}_eraint_${year}_1.nc ${var}_eraint_${year}_2.nc ${var}_eraint_${year}.nc
  74. rm -f ${var}_eraint_${year}_1.nc ${var}_eraint_${year}_2.nc
  75. ;;
  76. esac
  77. fi
  78. if [[ $nstep == 365 ]] ; then
  79. case $year in
  80. 1980|1984|1988|1992|1996|2000|2004|2008|2012|2016)
  81. ncks -O -d time,0,58 ${var}_eraint_${year}.nc ${var}_eraint_${year}_1.nc
  82. ncks -O -d time,60, ${var}_eraint_${year}.nc ${var}_eraint_${year}_2.nc
  83. ncrcat -O ${var}_eraint_${year}_1.nc ${var}_eraint_${year}_2.nc ${var}_eraint_${year}.nc
  84. rm -f ${var}_eraint_${year}_1.nc ${var}_eraint_${year}_2.nc
  85. ;;
  86. esac
  87. fi
  88. cp ${pathdfsin}/${var}_DFS4.3_${year}.nc ${var}_dfs4.3_${year}.nc
  89. ncks -A -v time ${var}_eraint_${year}.nc ${var}_dfs4.3_${year}.nc
  90. case $var in
  91. 'u10'|'v10'|'t2'|'q2') cdo setgrid,r320x161 ${var}_dfs4.3_${year}.nc ${var}_dfs4.3_${year}_bis.nc ;;
  92. 'qsw'|'qlw'|'snow'|'precip') cdo setgrid,r192x94 ${var}_dfs4.3_${year}.nc ${var}_dfs4.3_${year}_bis.nc ;;
  93. esac
  94. ncks -O -x -v lat_2,lon_2 ${var}_dfs4.3_${year}_bis.nc ${var}_dfs4.3_${year}.nc
  95. rm -f ${var}_dfs4.3_${year}_bis.nc
  96. if [[ $dfs2era == T ]] ; then
  97. cdo remapbic,r240x121 ${var}_dfs4.3_${year}.nc ${var}_dfs4.3_${year}_grideraint.nc
  98. cdo invertlat ${var}_dfs4.3_${year}_grideraint.nc ${var}_dfs4.3_${year}_grideraint_bis.nc
  99. rm -f ${var}_dfs4.3_${year}.nc ${var}_dfs4.3_${year}_grideraint.nc
  100. mv ${var}_dfs4.3_${year}_grideraint_bis.nc ${var}_dfs4.3_gridera_${year}.nc
  101. cdo sub ${var}_eraint_${year}.nc ${var}_dfs4.3_gridera_${year}.nc ${var}_eraint-dfs4.3_${year}.nc
  102. else
  103. case $var in
  104. 'u10'|'v10'|'t2'|'q2') cdo remapbic,r320x161 ${var}_eraint_${year}.nc ${var}_eraint_griddfs_${year}.nc ;;
  105. 'qsw'|'qlw'|'snow'|'precip') cdo remapbic,r192x94 ${var}_eraint_${year}.nc ${var}_eraint_griddfs_${year}.nc ;;
  106. esac
  107. rm -f ${var}_eraint_${year}.nc
  108. cdo sub ${var}_dfs4.3_${year}.nc ${var}_eraint_griddfs_${year}.nc ${var}_dfs4.3-eraint_${year}.nc
  109. fi
  110. done
  111. fi
  112. if [[ $ano == T ]] ; then
  113. length=30
  114. if [[ $dfs2era == T ]] ; then
  115. ncea -O -n $((${yearf}-${year0}+1)),4,1 ${var}_dfs4.3_gridera_${year0}.nc ${var}_dfs4.3_gridera_${year0}-${yearf}_clim.nc
  116. ncea -O -n $((${yearf}-${year0}+1)),4,1 ${var}_eraint_${year0}.nc ${var}_eraint_${year0}-${yearf}_clim.nc
  117. ncrcat -O ${var}_dfs4.3_gridera_${year0}-${yearf}_clim.nc ${var}_dfs4.3_gridera_${year0}-${yearf}_clim.nc ${var}_dfs4.3_gridera_${year0}-${yearf}_clim_bis.nc
  118. ncrcat -O ${var}_eraint_${year0}-${yearf}_clim.nc ${var}_eraint_${year0}-${yearf}_clim.nc ${var}_eraint_${year0}-${yearf}_clim_bis.nc
  119. cdo runmean,${length} ${var}_dfs4.3_gridera_${year0}-${yearf}_clim_bis.nc ${var}_dfs4.3_gridera_${year0}-${yearf}_clim_smoothed.nc
  120. ncks -O -d time,$(($nstep+1)),$(($nstep+$length/2)) ${var}_dfs4.3_gridera_${year0}-${yearf}_clim_smoothed.nc ${var}_dfs4.3_gridera_${year0}-${yearf}_clim_smoothed_1.nc
  121. ncks -O -d time,$(($length/2+1)),$nstep ${var}_dfs4.3_gridera_${year0}-${yearf}_clim_smoothed.nc ${var}_dfs4.3_gridera_${year0}-${yearf}_clim_smoothed_2.nc
  122. ncrcat -O ${var}_dfs4.3_gridera_${year0}-${yearf}_clim_smoothed_1.nc ${var}_dfs4.3_gridera_${year0}-${yearf}_clim_smoothed_2.nc ${var}_dfs4.3_gridera_${year0}-${yearf}_clim.nc
  123. rm -f ${var}_dfs4.3_gridera_${year0}-${yearf}_clim_bis.nc ${var}_dfs4.3_gridera_${year0}-${yearf}_clim_smoothed.nc ${var}_dfs4.3_gridera_${year0}-${yearf}_clim_smoothed_1.nc ${var}_dfs4.3_gridera_${year0}-${yearf}_clim_smoothed_2.nc
  124. cdo runmean,${length} ${var}_eraint_${year0}-${yearf}_clim_bis.nc ${var}_eraint_${year0}-${yearf}_clim_smoothed.nc
  125. ncks -O -d time,$(($nstep+1)),$(($nstep+$length/2)) ${var}_eraint_${year0}-${yearf}_clim_smoothed.nc ${var}_eraint_${year0}-${yearf}_clim_smoothed_1.nc
  126. ncks -O -d time,$(($length/2+1)),$nstep ${var}_eraint_${year0}-${yearf}_clim_smoothed.nc ${var}_eraint_${year0}-${yearf}_clim_smoothed_2.nc
  127. ncrcat -O ${var}_eraint_${year0}-${yearf}_clim_smoothed_1.nc ${var}_eraint_${year0}-${yearf}_clim_smoothed_2.nc ${var}_eraint_${year0}-${yearf}_clim.nc
  128. rm -f ${var}_eraint_${year0}-${yearf}_clim_bis.nc ${var}_eraint_${year0}-${yearf}_clim_smoothed.nc ${var}_eraint_${year0}-${yearf}_clim_smoothed_1.nc ${var}_eraint_${year0}-${yearf}_clim_smoothed_2.nc
  129. for ((year=$year0;year<=$yearf;year++)) ; do
  130. cdo sub ${var}_eraint_${year}.nc ${var}_eraint_${year0}-${yearf}_clim.nc ${var}_ano_eraint_${year}.nc
  131. cdo sub ${var}_dfs4.3_gridera_${year}.nc ${var}_dfs4.3_gridera_${year0}-${yearf}_clim.nc ${var}_ano_dfs4.3_gridera_${year}.nc
  132. cdo sub ${var}_ano_eraint_${year}.nc ${var}_ano_dfs4.3_gridera_${year}.nc ${var}_ano_eraint-dfs4.3_${year}.nc
  133. rm -f ${var}_eraint_${year}.nc ${var}_dfs4.3_gridera_${year}.nc ${var}_ano_eraint_${year}.nc ${var}_ano_dfs4.3_gridera_${year}.nc
  134. done
  135. else
  136. ncea -O -n $((${yearf}-${year0}+1)),4,1 ${var}_dfs4.3_${year0}.nc ${var}_dfs4.3_${year0}-${yearf}_clim.nc
  137. ncea -O -n $((${yearf}-${year0}+1)),4,1 ${var}_eraint_griddfs_${year0}.nc ${var}_eraint_griddfs_${year0}-${yearf}_clim.nc
  138. ncrcat -O ${var}_dfs4.3_${year0}-${yearf}_clim.nc ${var}_dfs4.3_${year0}-${yearf}_clim.nc ${var}_dfs4.3_${year0}-${yearf}_clim_bis.nc
  139. ncrcat -O ${var}_eraint_griddfs_${year0}-${yearf}_clim.nc ${var}_eraint_griddfs_${year0}-${yearf}_clim.nc ${var}_eraint_griddfs_${year0}-${yearf}_clim_bis.nc
  140. cdo runmean,${length} ${var}_dfs4.3_${year0}-${yearf}_clim_bis.nc ${var}_dfs4.3_${year0}-${yearf}_clim_smoothed.nc
  141. ncks -O -d time,$(($nstep+1)),$(($nstep+$length/2)) ${var}_dfs4.3_${year0}-${yearf}_clim_smoothed.nc ${var}_dfs4.3_${year0}-${yearf}_clim_smoothed_1.nc
  142. ncks -O -d time,$(($length/2+1)),$nstep ${var}_dfs4.3_${year0}-${yearf}_clim_smoothed.nc ${var}_dfs4.3_${year0}-${yearf}_clim_smoothed_2.nc
  143. ncrcat -O ${var}_dfs4.3_${year0}-${yearf}_clim_smoothed_1.nc ${var}_dfs4.3_${year0}-${yearf}_clim_smoothed_2.nc ${var}_dfs4.3_${year0}-${yearf}_clim.nc
  144. rm -f ${var}_dfs4.3_${year0}-${yearf}_clim_bis.nc ${var}_dfs4.3_${year0}-${yearf}_clim_smoothed.nc ${var}_dfs4.3_${year0}-${yearf}_clim_smoothed_1.nc ${var}_dfs4.3_${year0}-${yearf}_clim_smoothed_2.nc
  145. cdo runmean,${length} ${var}_eraint_griddfs_${year0}-${yearf}_clim_bis.nc ${var}_eraint_griddfs_${year0}-${yearf}_clim_smoothed.nc
  146. ncks -O -d time,$(($nstep+1)),$(($nstep+$length/2)) ${var}_eraint_griddfs_${year0}-${yearf}_clim_smoothed.nc ${var}_eraint_griddfs_${year0}-${yearf}_clim_smoothed_1.nc
  147. ncks -O -d time,$(($length/2+1)),$nstep ${var}_eraint_griddfs_${year0}-${yearf}_clim_smoothed.nc ${var}_eraint_griddfs_${year0}-${yearf}_clim_smoothed_2.nc
  148. ncrcat -O ${var}_eraint_griddfs_${year0}-${yearf}_clim_smoothed_1.nc ${var}_eraint_griddfs_${year0}-${yearf}_clim_smoothed_2.nc ${var}_eraint_griddfs_${year0}-${yearf}_clim.nc
  149. rm -f ${var}_eraint_griddfs_${year0}-${yearf}_clim_bis.nc ${var}_eraint_griddfs_${year0}-${yearf}_clim_smoothed.nc ${var}_eraint_griddfs_${year0}-${yearf}_clim_smoothed_1.nc ${var}_eraint_griddfs_${year0}-${yearf}_clim_smoothed_2.nc
  150. for ((year=$year0;year<=$yearf;year++)) ; do
  151. cdo sub ${var}_eraint_griddfs_${year}.nc ${var}_eraint_griddfs_${year0}-${yearf}_clim.nc ${var}_ano_eraint_griddfs_${year}.nc
  152. cdo sub ${var}_dfs4.3_${year}.nc ${var}_dfs4.3_${year0}-${yearf}_clim.nc ${var}_ano_dfs4.3_${year}.nc
  153. cdo sub ${var}_ano_dfs4.3_${year}.nc ${var}_ano_eraint_griddfs_${year}.nc ${var}_ano_dfs4.3-eraint_${year}.nc
  154. rm -f ${var}_eraint_griddfs_${year}.nc ${var}_dfs4.3_${year}.nc ${var}_ano_eraint_griddfs_${year}.nc ${var}_ano_dfs4.3_${year}.nc
  155. done
  156. fi
  157. fi
  158. if [[ $reorg == T ]] ; then
  159. for ((jt=1;jt<=$nstep;jt++)) ; do
  160. ncrcat -O -d time,$((jt-1)),,$nstep -n $((yearf-year0+1)),4,1 ${var}_${wih}${dif}_${year0}.nc ${var}_${wih}${dif}_${year0}-${yearf}_$jt.nc
  161. done
  162. mkdir -p ${wih}${dir0}
  163. mv ${var}_${wih}${dif}_* ${wih}${dir0}/.
  164. fi
  165. if [[ $raw == T && $ano == F ]] ; then
  166. for ((year=$year0;year<=$yearf;year++)) ; do
  167. if [[ $dfs2era == T ]] ; then
  168. rm -f ${var}_eraint_${year}.nc ${var}_dfs4.3_gridera_${year}.nc
  169. else
  170. rm -f ${var}_eraint_griddfs_${year}.nc ${var}_dfs4.3_${year}.nc
  171. fi
  172. done
  173. fi
  174. if [[ $monmean == T ]] ; then
  175. jt0=1
  176. for ((mon=1;mon<=12;mon++)) ; do
  177. case $mon in
  178. 1|3|5|7|8|10|12) ndays=31 ;;
  179. 4|6|9|11) ndays=30 ;;
  180. 2) ndays=28 ;;
  181. esac
  182. lstfiles=""
  183. case $nstep in
  184. 1460) ntimes=$((ndays*4+jt0-1)) ;;
  185. 365) ntimes=$((ndays+jt0-1)) ;;
  186. 12) ntimes=1 ;;
  187. esac
  188. for ((jt=$jt0;jt<=$ntimes;jt++)) ;do
  189. lstfiles=$lstfiles" "${wih}${dir0}/${var}_${wih}${dif}_${year0}-${yearf}_$jt.nc
  190. done
  191. ncea -O $lstfiles ${wih}${dir0}/${var}_${wih}${dif}_${year0}-${yearf}_mon$(printf "%02d" ${mon}).nc
  192. case $nstep in
  193. 1460) jt0=$((${jt0}+ndays*4)) ;;
  194. 365) jt0=$((${jt0}+ndays)) ;;
  195. 12) jt0=$((${jt0}+1)) ;;
  196. esac
  197. done
  198. fi
  199. done
  200. if [[ $pickup1 == T ]] ; then
  201. if [[ $monmean == T ]] ; then
  202. dirpert=perturb1_${dir0}_mon
  203. nstep=12
  204. else
  205. dirpert=perturb1_${dir0}
  206. fi
  207. mkdir -p $dirpert
  208. RANGE=$((${yearf}-${year0}+1))
  209. for ((jt=1;jt<=$nstep;jt++)) ; do
  210. for memb in ${lstmbs[@]} ; do
  211. for ((year=$year1;year<=$year2;year++)) ; do
  212. number=$((RANDOM%${RANGE}))
  213. for var in ${lstvars[@]} ; do
  214. if [[ $monmean == T ]] ; then
  215. filein=${var}_${wih}${dif}_${year0}-${yearf}_mon$(printf "%02d" ${jt}).nc
  216. else
  217. filein=${var}_${wih}${dif}_${year0}-${yearf}_$jt.nc
  218. fi
  219. ncks -O -d time,$number ${wih}${dir0}/${filein} ${dirpert}/${var}_fc${memb}_${year}_$(printf "%04d" $jt).nc
  220. done
  221. done
  222. done
  223. done
  224. fi
  225. if [[ $pickup2 == T ]] ; then
  226. mkdir -p perturb2_${dir0}
  227. RANGE=$((${yearf}-${year0}+1))
  228. for ((jt=1;jt<=$nstep;jt++)) ; do
  229. for memb in ${lstmbs[@]} ; do
  230. for ((year=$year1;year<=$year2;year++)) ; do
  231. for ((jlaunch=1;jlaunch<=2;jlaunch++)) ; do
  232. number=$((RANDOM%${RANGE}))
  233. for var in ${lstvars[@]} ; do
  234. ncks -O -d time,$number ${wih}${dir0}/${var}_${wih}${dif}_${year0}-${yearf}_$jt.nc perturb2_${dir0}/${var}_fc${memb}_${year}_$(printf "%04d" $jt)_$jlaunch.nc
  235. done
  236. done
  237. for var in ${lstvars[@]} ; do
  238. ncea -O perturb2_${dir0}/${var}_fc${memb}_${year}_$(printf "%04d" $jt)_1.nc perturb2_${dir0}/${var}_fc${memb}_${year}_$(printf "%04d" $jt)_2.nc perturb2_${dir0}/${var}_fc${memb}_${year}_$(printf "%04d" $jt).nc
  239. rm -f perturb2_${dir0}/${var}_fc${memb}_${year}_$(printf "%04d" $jt)_1.nc perturb2_${dir0}/${var}_fc${memb}_${year}_$(printf "%04d" $jt)_2.nc
  240. done
  241. done
  242. done
  243. done
  244. fi
  245. if [[ $pickup1 == T || $pickup2 == T ]] ; then
  246. lstdirs=""
  247. if [[ $pickup1 == T ]] ; then
  248. if [[ $monmean == T ]] ; then
  249. lstdirs=$lstdirs" "perturb1_${dir0}_mon
  250. else
  251. lstdirs=$lstdirs" "perturb1_${dir0}
  252. fi
  253. fi
  254. if [[ $pickup2 == T ]] ; then
  255. lstdirs=$lstdirs" "perturb2_${dir0}
  256. fi
  257. for dir in $lstdirs ; do
  258. for memb in ${lstmbs[@]} ; do
  259. for ((year=$year1;year<=$year2;year++)) ; do
  260. for var in ${lstvars[@]} ; do
  261. ncrcat -O -n $nstep,4,1 ${dir}/${var}_fc${memb}_${year}_0001.nc ${dir}/${var}_fc${memb}_${year}.nc
  262. rm -f ${dir}/${var}_fc${memb}_${year}_*.nc
  263. if [[ $monmean == T ]] ; then
  264. cdo settaxis,${year}-01-15,12:00,1mon ${dir}/${var}_fc${memb}_${year}.nc ${dir}/${var}_fc${memb}_${year}_bis.nc
  265. rm ${dir}/${var}_fc${memb}_${year}.nc
  266. mv ${dir}/${var}_fc${memb}_${year}_bis.nc ${dir}/${var}_fc${memb}_${year}.nc
  267. fi
  268. if [[ $dfs2era == T && $monmean == F ]] ; then
  269. case $year in
  270. 1980|1984|1988|1992|1996|2000|2004|2008|2012|2016|2020)
  271. case $nstep in
  272. 1460)
  273. ncks -O -d time,0,232 ${dir}/${var}_fc${memb}_${year}.nc ${dir}/${var}_fc${memb}_${year}_1.nc
  274. ncks -O -d time,229,232 ${dir}/${var}_fc${memb}_${year}.nc ${dir}/${var}_fc${memb}_${year}_2.nc
  275. ncks -O -d time,233, ${dir}/${var}_fc${memb}_${year}.nc ${dir}/${var}_fc${memb}_${year}_3.nc
  276. ;;
  277. 365)
  278. ncks -O -d time,0,58 ${dir}/${var}_fc${memb}_${year}.nc ${dir}/${var}_fc${memb}_${year}_1.nc
  279. ncks -O -d time,58 ${dir}/${var}_fc${memb}_${year}.nc ${dir}/${var}_fc${memb}_${year}_2.nc
  280. ncks -O -d time,59, ${dir}/${var}_fc${memb}_${year}.nc ${dir}/${var}_fc${memb}_${year}_3.nc
  281. ;;
  282. esac
  283. ncrcat -O ${dir}/${var}_fc${memb}_${year}_1.nc ${dir}/${var}_fc${memb}_${year}_2.nc ${dir}/${var}_fc${memb}_${year}_3.nc ${dir}/${var}_fc${memb}_${year}.nc
  284. rm -f ${dir}/${var}_fc${memb}_${year}_1.nc ${dir}/${var}_fc${memb}_${year}_2.nc ${dir}/${var}_fc${memb}_${year}_3.nc
  285. esac
  286. fi
  287. done
  288. done
  289. done
  290. done
  291. fi
  292. if [[ $monmean == T ]] ; then
  293. for memb in ${lstmbs[@]} ; do
  294. for var in ${lstvars[@]} ; do
  295. ncrcat -O -n $((${year2}-${year1}+1)),4,1 perturb1_${dir0}_mon/${var}_fc${memb}_${year1}.nc perturb1_${dir0}_mon/${var}_fc${memb}_${year1}-${year2}.nc
  296. cdo inttime,${year1}-01-15,12:00,6hour perturb1_${dir0}_mon/${var}_fc${memb}_${year1}-${year2}.nc perturb1_${dir0}_mon/${var}_fc${memb}_${year1}-${year2}_6hourly.nc
  297. rm -f perturb1_${dir0}_mon/${var}_fc${memb}_${year1}-${year2}.nc
  298. cdo splityear perturb1_${dir0}_mon/${var}_fc${memb}_${year1}-${year2}_6hourly.nc perturb1_${dir0}_mon/${var}_fc${memb}_
  299. rm -f perturb1_${dir0}_mon/${var}_fc${memb}_${year1}-${year2}_6hourly.nc
  300. if [[ $dfs2era == F ]] ; then
  301. lstyears=( 1960 1964 1968 1972 1976 1980 1984 1988 1992 1996 2000 2004 2008 2012 2016 2020 )
  302. for year in ${lstyears[@]} ; do
  303. if [[ -e perturb1_${dir0}_mon/${var}_fc${memb}_${year}.nc ]] ; then
  304. case $nstep in
  305. 1460)
  306. ncks -O -d time,0,232 perturb1_${dir0}_mon/${var}_fc${memb}_${year}.nc perturb1_${dir0}_mon/${var}_fc${memb}_${year}_1.nc
  307. ncks -O -d time,237, perturb1_${dir0}_mon/${var}_fc${memb}_${year}.nc perturb1_${dir0}_mon/${var}_fc${memb}_${year}_2.nc
  308. ;;
  309. 365)
  310. ncks -O -d time,0,58 perturb1_${dir0}_mon/${var}_fc${memb}_${year}.nc perturb1_${dir0}_mon/${var}_fc${memb}_${year}_1.nc
  311. ncks -O -d time,60, perturb1_${dir0}_mon/${var}_fc${memb}_${year}.nc perturb1_${dir0}_mon/${var}_fc${memb}_${year}_2.nc
  312. ;;
  313. esac
  314. ncrcat -O perturb1_${dir0}_mon/${var}_fc${memb}_${year}_1.nc perturb1_${dir0}_mon/${var}_fc${memb}_${year}_2.nc perturb1_${dir0}_mon/${var}_fc${memb}_${year}.nc
  315. rm -f perturb1_${dir0}_mon/${var}_fc${memb}_${year}_1.nc perturb1_${dir0}_mon/${var}_fc${memb}_${year}_2.nc
  316. fi
  317. done
  318. fi
  319. done
  320. done
  321. fi