REAL FUNCTION RelHum (T, P, R)
implicit none
real, intent(IN) :: T, P, R
real :: Es, Rs
! Calculate the saturation vapor pressure at this temperature
Es = 6.111 * exp( (17.67*(T-273.15)) / ((T-273.15)+245.5) )
! Calculate the saturation mixing ratio
Rs = 0.62 * Es / ( P - Es )
! The relative humidity is a ratio of the given mixing ratio to saturation
RelHum = R / Rs * 100
END FUNCTION RelHum