interp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/usr/bin/env bash
  2. #
  3. # interp, scrip_use and scrip_use_extrap have been written by Virginie Guemas
  4. # in 2011 based on SCRIP software that computes interpolation weights:
  5. # Spherical Coordinate Remapping and Interpolation Package
  6. #
  7. #~~~~~~~~~~~~~~~
  8. # get arguments
  9. #~~~~~~~~~~~~~~~
  10. if [ $# == 0 ]; then
  11. echo
  12. echo "USAGE: $(basename $0) <input_file> <input_var> <method> <gridin> <gridout> <output_file> <debug>"
  13. echo "<method> can be bilinear/bicubic/conserv/distwgt"
  14. echo "<gridin> and <gridout> can be ORCA1t_v2.2/ORCA1t_v3.2/ORCA025t_v3.2/ERA40/ERAint/EcEarth2/EcEarth3/HadISST/NCEP/NOAAv3b/NSIDC"
  15. echo "<debug> optional argument in case default choices not convenient : TRUE/FALSE"
  16. exit 1
  17. fi
  18. filein=$1
  19. varin=$2
  20. method=$3
  21. gridin=$4
  22. gridout=$5
  23. fileout=$6
  24. if [ $# == 7 ]; then
  25. debug=$7
  26. else
  27. debug='FALSE'
  28. fi
  29. exec='scrip_use'
  30. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  31. # /cfu/data conventions or not ?
  32. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33. case $gridin in
  34. 'ORCA1t_v2.2'|'ORCA1t_v3.2'|'ORCA025t_v3.2'|'NSIDC')
  35. flag1='FALSE'
  36. ;;
  37. 'NCEP'|'ERAint'|'ERA40'|'EcEarth2'|'EcEarth3'|'HadISST'|'NOAAv3b')
  38. flag1='TRUE'
  39. ;;
  40. *)
  41. flag1='FALSE'
  42. ;;
  43. esac
  44. case $gridin in
  45. 'ERA40'|'ERAint'|'EcEarth2'|'EcEarth3'|'HadISST'|'NCEP'|'NOAAv3b'|'NSIDC')
  46. flag2='TRUE'
  47. ;;
  48. 'ORCA1t_v2.2'|'ORCA1t_v3.2'|'ORCA025t_v3.2')
  49. flag2='FALSE'
  50. ;;
  51. *)
  52. flag2='FALSE'
  53. ;;
  54. esac
  55. #~~~~~~~~~~~~~~~~~~~~
  56. # land data or not ?
  57. #~~~~~~~~~~~~~~~~~~~~
  58. case $varin in
  59. 'tas'|'prlr'|'g500'|'g200'|'psl'|'hflsd'|'hfssd'|'hus'|'rls'|'rss'|'rsds'|'vas'|'uas'|'tasmax'|'tasmin') ;;
  60. 'tos'|'ice'|'mld'|'sic'|'sit'|'sea_ice_area_fraction') gridin=${gridin}'_ocean' ;;
  61. 'ice_pres'|'somixhgt'|'sosstsst'|'sosaline'|'iicethic'|'ileadfra'|'isnowthi'|'iicetemp'|'somxl010'|'somxlheatc'|'somxlsaltc'|'sobarstfu'|'sobarstfv'|'sobarstf'|'heatc_sl'|'vertmeansal'|'votemper'|'vosaline'|'rhopn') gridout=${gridout}'_ocean' ;;
  62. *) echo "unexpected input variable : contact Virginie" ; exit 1 ;;
  63. esac
  64. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  65. # Weigths available or not ?
  66. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  67. if [[ ! -e /cfu/pub/scripts/interpolation/weigths/rmp_${gridin}_to_${gridout}_${method}.nc ]] ; then
  68. echo "unexpected input or output grid : contact Virginie"
  69. exit 1
  70. fi
  71. #~~~~~~~~~~~~~~~
  72. # Interpolation
  73. #~~~~~~~~~~~~~~~
  74. if [[ ! -e ${filein} ]] ; then
  75. echo ${filein}" does not exist"
  76. exit 1
  77. fi
  78. vars=`cdo showvar ${filein}`
  79. exist='FALSE'
  80. for var in $vars ; do
  81. if [[ $var == ${varin} ]] ; then exist='TRUE' ; fi
  82. done
  83. if [[ $exist == 'FALSE' ]] ; then
  84. echo $var" is not in input file"
  85. exit 1
  86. fi
  87. cat > scrip_use_in <<EOF
  88. &remap_inputs
  89. remap_wgt = '/cfu/pub/scripts/interpolation/weigths/rmp_${gridin}_to_${gridout}_${method}.nc'
  90. infile = '${filein}'
  91. invertlat = ${flag1}
  92. var = '${varin}'
  93. fromregular = ${flag2}
  94. outfile = '${fileout}'
  95. /
  96. EOF
  97. ln -sf /cfu/pub/scripts/interpolation/${exec} ${exec}
  98. ./${exec}
  99. if [[ $debug == 'FALSE' ]] ; then
  100. rm -f ${exec} scrip_use_in
  101. else
  102. ln -sf /cfu/pub/scripts/interpolation/${exec}_extrap ${exec}_extrap
  103. fi