library.bash 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. function extrap {
  2. typeset var restartin=$1
  3. typeset var var=$2
  4. typeset var meshin=$3
  5. typeset var lon=$4
  6. typeset var lat=$5
  7. typeset var maskextrap=$6
  8. typeset var maskclim=$7
  9. typeset var varmask=$8
  10. typeset var restartout=$9
  11. typeset var flag=${10}
  12. typeset var cfutools=${11}
  13. typeset var confout=${12}
  14. typeset var mon=${13}
  15. typeset var fac
  16. case $flag in
  17. '3d') script=${cfutools}/interpolation/extrap.py ;;
  18. '2d') script=${cfutools}/interpolation/extrap2d.py ;;
  19. esac
  20. python ${script} ${restartin} ${var} ${meshin} ${lon} ${lat} ${maskextrap} ${varmask} tmp1.nc
  21. cdo ltc,0.5 -selvar,${varmask} ${maskclim} tmp.nc
  22. case $var in
  23. 'tn'|'tb'|'votemper')
  24. cdo ifthenelse -chvar,${varmask},$var tmp.nc tmp1.nc -chvar,votemper,$var /cfu/pub/scripts/prep_restarts/auxfiles/filesclim/${confout}/temperature_m$mon.nc ${restartout}
  25. ;;
  26. 'sst_m')
  27. cdo mulc,5 /cfu/pub/scripts/prep_restarts/auxfiles/filesclim/${confout}/sst_m$mon.nc titi.nc
  28. cdo ifthenelse -chvar,${varmask},$var tmp.nc tmp1.nc -chvar,votemper,$var titi.nc ${restartout}
  29. rm -f titi.nc
  30. ;;
  31. 'sst_io')
  32. cdo addc,273.15 /cfu/pub/scripts/prep_restarts/auxfiles/filesclim/${confout}/sst_m$mon.nc titi.nc
  33. cdo mulc,2 titi.nc toto.nc
  34. cdo ifthenelse -chvar,${varmask},$var tmp.nc tmp1.nc -chvar,votemper,$var toto.nc ${restartout}
  35. rm -f titi.nc toto.nc
  36. ;;
  37. 'sn'|'sb'|'vosaline')
  38. cdo ifthenelse -chvar,${varmask},$var tmp.nc tmp1.nc -chvar,vosaline,$var /cfu/pub/scripts/prep_restarts/auxfiles/filesclim/${confout}/salinity_m$mon.nc ${restartout}
  39. ;;
  40. 'sss_m'|'sss_io')
  41. case $var in
  42. 'sss_m' ) fac=5;;
  43. 'sss_io') fac=2;;
  44. esac
  45. cdo mulc,$fac /cfu/pub/scripts/prep_restarts/auxfiles/filesclim/${confout}/sss_m$mon.nc titi.nc
  46. cdo ifthenelse -chvar,${varmask},$var tmp.nc tmp1.nc -chvar,vosaline,$var titi.nc ${restartout}
  47. rm -f titi.nc
  48. ;;
  49. *)
  50. cdo ifthenelse -chvar,${varmask},$var tmp.nc tmp1.nc -chvar,${varmask},$var tmp.nc ${restartout}
  51. ;;
  52. esac
  53. rm -f tmp.nc tmp1.nc
  54. }
  55. function gathervar {
  56. typeset var restfile=$1
  57. typeset var newvar=$2
  58. if [[ -e ${restfile} ]] ; then
  59. ncks -A ${newvar} ${restfile}
  60. else
  61. cp ${newvar} ${restfile}
  62. fi
  63. }
  64. function applymask {
  65. typeset var maskfile=$1
  66. typeset var maskvar=$2
  67. typeset var file=$3
  68. typeset var varname=$4
  69. typeset var outfile=$5
  70. cdo selvar,$maskvar $maskfile tmpmask.nc
  71. cdo ifthen -chvar,${maskvar},${varname} tmpmask.nc $file $outfile
  72. rm -f tmpmask.nc
  73. }