%% temppawt0g0.m calculates the requred base temperature and gradients
%% required by the Titheridge model. The polynominal values given here 
%% are derived by pwtpfit5.m and were produced using a base height of 
%% 400km.
%% Note - points with sl<0.05 are reset to sL=0.05.
%%
%%
%% Author: Phillip A. Webb
%% Last updated: June 9 2004                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
%%

function [t0d,t0n,g0d,g0n]=temppawt0g0(sl)

% sl = sL values of the points of interest
% t0d = day base temperature (K)
% t0n = night base temperature (K)
% g0d = day base gradient (K/km)
% g0n = night base gradient (K/km)

%Reset required sL terms
sl(sl<0.05)=0.05;

%Polynominal coefficents from pwtpfit5.m
load pwt0g0

%Calculate required values
t0d=polyval(t0dp,sl);
t0n=polyval(t0np,sl);
g0d=polyval(g0dp,sl);
g0n=polyval(g0np,sl);

%Add in a correction so the that day and night values agree at sL=1 (this is not
%currently done by the fit from pwtpfit4.m). Use a sine weighting for points
%above sL>0.9.
poic=sl>0.9;
if any(any(poic))
 t0d0=t0d;
 t0n0=t0n;
 g0d0=g0d;
 g0n0=g0n;
 wt=sin(((sl(poic)-0.9)/0.2).*(pi/2)).^2;
 t0d(poic)=(1-wt).*t0d0(poic)+wt.*t0n0(poic);
 t0n(poic)=(1-wt).*t0n0(poic)+wt.*t0d0(poic);
 g0d(poic)=(1-wt).*g0d0(poic)+wt.*g0n0(poic);
 g0n(poic)=(1-wt).*g0n0(poic)+wt.*g0d0(poic);
end
