% Version 1.0 released by David Romps on April 15, 2021.
% 
% When using this code, please cite:
% 
% @article{20dewpoint,
%   Title   = {Accurate expressions for the dew point and frost point derived from the {Rankine-Kirchhoff} approximations},
%   Author  = {David M. Romps},
%   Journal = {Journal of the Atmospheric Sciences},
%   Year    = {2021},
%   Month   = jul,
%   Number  = {7},
%   Pages   = {2113--2116},
%   Volume  = {78}
% }
%
% This dew-point function returns the dewpoint (Td) in K.
% The inputs are:
% - p in Pascals
% - T in Kelvins
% - Exactly one of rh, rhl, and rhs (dimensionless, from 0 to 1):
%    * The value of rh is interpreted to be the relative humidity with
%      respect to liquid water if T >= 273.15 K and with respect to ice if
%      T < 273.15 K. 
%    * The value of rhl is interpreted to be the relative humidity with
%      respect to liquid water
%    * The value of rhs is interpreted to be the relative humidity with
%      respect to ice
% - return_fp is an optional logical flag.  If true, the frost point (Tf)
%   is returned instead of the dew point (Td). 
% - return_max_dp_fp is an optional logical flag.  If true, the maximum of the
%   dew point (Td) and frost point (Tf) is returned.
%
% Since MATLAB does not allow optional input variables or default values
% for input variables, this function has been written to only allow the 
% input of rhl.  If you like unsolicited advice, do not use MATLAB.  R
% and Python are free and better.

if (abs(dewpoint(300,.5,false,false)/288.7153070587-1) < 1e-10) && ...
   (abs(dewpoint(200,.5,false,false)/195.3232095158-1) < 1e-10) && ...
   (abs(dewpoint(300,.5,true ,false)/286.6935602684-1) < 1e-10) && ...
   (abs(dewpoint(200,.5,true ,false)/200.0743709369-1) < 1e-10);
   disp('Success')
else
   disp('Failure')
end
