comp_q2.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #/bin/ksh
  2. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3. # This script computes the specific humidity from the dew point using :
  4. #
  5. # 1) the approximation e<<P which gives q=0.622(e/P)=0.622(es(Td)/P)
  6. #
  7. # 2) And one of the three formulas :
  8. #
  9. # - the August-Roche-Magnus formula : es=C1 x exp( (A1 x T)/(B1 + T) )
  10. # A1=17.625, B1=243.04°C, C1=6.1094 hPa
  11. # whose error <= 0.4% in the range -40°C < T < 50°C.
  12. # from Alduchov and Eskridge (1996) Ueber die Berechnung der Expansivkraft
  13. # des Wasserdunstes. Ann. Phys. Chem., 13, 122–137.
  14. #
  15. # - the Lawrence formula : es=C2 x exp( -L/(R*(T+273.15)) )
  16. # C2=2.53e9 hPa, L=2.501e6 J.kg-1, R=461.5 J.K-1.kg-1
  17. # from Lawrence (2005), BAMS, 86, 225-233
  18. #
  19. # - the Tetens formula : es= (D1 + E1*P) x C1 x exp((A1 x T)/(B1 + T) )
  20. # D1=1.0007 hPa, E1=3.46e-6, C1=6.1121 hPa, B1=240.97°C, A1=17.502
  21. # from Buck, 181, JAM, 20, 1527-1532
  22. #
  23. # Review : Gibbins (1990) Ann. Geophys., 8, 859–885.
  24. #
  25. # History : Virginie Guemas - Initial version - 2012
  26. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. # Arguments
  28. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  29. year0='2012'
  30. yearf='2014'
  31. equation='Lawrence'
  32. fileD='/cfu/scratch/vguemas/ERAint/d2m_eraint' # Dew point
  33. fileP='/cfu/scratch/vguemas/ERAint/sp_eraint' # Surface pressure
  34. fileout='q2_eraint'
  35. varD="d2m"
  36. varP='sp'
  37. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  38. for ((year=${year0};year<=${yearf};year++)) ; do
  39. ncap -s ${varD}"=double("${varD}")" ${fileD}_${year}.nc tmp1_${year}.nc
  40. cdo subc,273.15 tmp1_${year}.nc tmp_${year}.nc
  41. ncap -s ${varP}"=double("${varP}")" ${fileP}_${year}.nc toto_${year}.nc
  42. case $equation in
  43. 'Magnus') cdo expr,'esd=6.1094*exp((17.625*'${varD}')/(243.04+'${varD}'));' tmp_${year}.nc tmp2_${year}.nc ;;
  44. 'Lawrence') cdo expr,'esd=2.53e9*exp(((d2m+273.15)^(-1))*(-2.501e6/461.5));' tmp_${year}.nc tmp2_${year}.nc ;;
  45. 'Tetens') cdo expr,'esd=(1.0007+3.46e-6*1013)*6.1121*exp((17.502*d2m)/(240.97+d2m));' tmp_${year}.nc tmp2_${year}.nc ;;
  46. esac
  47. ncks -A -v sp toto_${year}.nc tmp2_${year}.nc
  48. cdo expr,'q2=0.622*esd/(sp/100)' tmp2_${year}.nc ${fileout}_${year}.nc
  49. rm -f tmp_${year}.nc tmp1_${year}.nc tmp2_${year}.nc toto_${year}.nc
  50. done