build_Tofill.bash 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/bash
  2. set -evx
  3. #
  4. # This script prepares the Tofill.nc file to be split afterwards between
  5. # Tofill.clim.nc and Tofill.extrap.nc
  6. #
  7. # History : Virginie Guemas - Initial version March 2014
  8. #
  9. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  10. # Arguments
  11. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  12. restart=$1 # Output restart after skipping the extrapolation and filling of
  13. # empty seas to be able to compute Tofill.nc
  14. meshmask=$2 # Mask of the grid that restart should have after extrapolation
  15. # and filling of empty seas
  16. Tofill=$3 # Name of the output Tofill.nc file
  17. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. lstmasks=('tmask' 'umask' 'vmask' 'fmask')
  19. cdo setmisstoc,1e19 $1 tmp1.nc
  20. cdo gtc,1e18 tmp1.nc tmp2.nc
  21. for mask in ${lstmasks[@]} ; do
  22. case $mask in
  23. 'tmask' ) var='tn';;
  24. 'umask' ) var='un';;
  25. 'vmask' ) var='vn';;
  26. 'fmask' ) var='rotn';;
  27. esac
  28. cdo selvar,$var tmp2.nc tmp2_${var}.nc
  29. cdo add -chvar,$var,$mask tmp2_${var}.nc -selvar,$mask $2 sum.nc
  30. cdo gtc,1.5 sum.nc Tofill_${mask}.nc
  31. rm -f tmp2_${var}.nc sum.nc
  32. if [ -e $3 ] ; then
  33. ncks -A Tofill_${mask}.nc $3
  34. rm -f Tofill_${mask}.nc
  35. else
  36. mv Tofill_${mask}.nc $3
  37. fi
  38. done
  39. rm -f tmp1.nc tmp2.nc
  40. echo "You have just built Tofill.nc : "$3
  41. echo "Now you can use :"
  42. echo " 1) cdo setcindexbox,c,idx1,idx2,idy1,idy2 ifile ofile to set seas at 0"
  43. echo " and build Tofill.extrap.nc"
  44. echo " 2) cdo sub to get Tofill.clim.nc from Tofill.nc and Tofill.extrap.nc"