"""This script makes a plot of the constant-L approximation
for the saturation vapor pressure for water, switching
from sublimation to vaporization latent heat at the triple point
"""

#Data on section of text which this script is associated with
#**ToDo: Chapter and Figure references can be given in terms of
#LaTeX labels, which can then be turned into numbers using
#information in the .aux files LaTeX produces. This isn't so
#necessary for the Chapter refs, which won't change much, but
#it would be useful for the Figure refs.
Chapter = '2.**'
Figure = '**'
#

import phys,Numeric
from ClimateUtilities import *
#

stuff = phys.water # Put your favorite substance here

#Set up a list of temperatures
Tlist = [200. + i for i in range(121)]

#Make empty lists to hold results of the three calculations
psatw = []
psati = []

#Compute the three saturation vapor pressures by looping
#over the temperatures in the list. Append the results
#to the appropriate lists.
satvps_w = phys.satvps_function(
    stuff.TriplePointT,stuff.TriplePointP,stuff.MolecularWeight,stuff.L_vaporization)
satvps_i = phys.satvps_function(
    stuff.TriplePointT,stuff.TriplePointP,stuff.MolecularWeight,stuff.L_sublimation)
for T in Tlist:
    psatw.append(satvps_w(T)) #Exponential form based on L for water
    psati.append(satvps_i(T)) #Exponential form based on L for ice


#Put the results in a data structure for plotting
c = Curve()
c.addCurve(Tlist,'T','Temperature')
c.addCurve(psatw,'ps_w','Constant L approx (water)')
c.addCurve(psati,'ps_i','Constant L approx (ice)')

#
# Set the plotting options. We use a logarithmic axis because the saturation
# vapor pressure varies over such a great range
c.YlogAxis = True

#Do the plot. 
plot(c)
#
#Write out to file
c.dump()
