subroutine guess(tout, tind, nlayer, gap, thick, width, theta, Ebb, Ebf, Tgap)
!***********************************************************************
! purpose - initializes temperature distribution assuming
! a constant temperature gradient across the window
!***********************************************************************
! Input
! tout outdoor air temperature (k)
! tind indoor air temperature (k)
! nlayer number of solid layers in window output
! gap thickness of gas gaps (m)
! thick thickness of glazing layers (m)
! Output
! width total width of the glazing system
! theta array of surface temps starting from outdoor layer (k)
! Ebb vector of emissive power (?) of the back surface (# of layers)
! Ebf vector of emissive power (?) of the front surface (# of layers)
! Locals
! x Vector of running width
! delta delta T per unit length
integer, intent(in) :: nlayer
real(r64), intent(in) :: tout, tind
real(r64), dimension(MaxGap), intent(in) :: gap
real(r64), dimension(maxlay), intent(in) :: thick
real(r64), intent(out) :: width
real(r64), dimension(maxlay), intent(out) :: Ebb, Ebf
real(r64), dimension(maxlay1), intent(out) :: Tgap
real(r64), dimension(maxlay2), intent(out) :: theta
real(r64), dimension(maxlay2) :: x
real(r64) :: delta
integer :: i, j, k
x(1) = 0.001d0
x(2) = x(1)+thick(1)
do i = 2, nlayer
j = 2*i - 1
k = 2*i
x(j) = x(j-1) + gap(i-1)
x(k) = x(k-1) + thick(i)
end do
width = x(nlayer*2)+0.01d0
delta = (tind-tout)/width
if (delta.eq.0.0d0) then
delta = TemperatureQuessDiff/width
end if
do i=1, nlayer
j = 2*i
theta(j-1) = tout + x(j-1)*delta
theta(j) = tout + x(j)*delta
Ebf(i) = StefanBoltzmann * theta(j-1)**4
Ebb(i) = StefanBoltzmann * theta(j)**4
end do
do i =1, nlayer + 1
if (i.eq.1) then
Tgap(1) = tout
else if (i.eq.(nlayer + 1)) then
Tgap(nlayer + 1) = tind
else
Tgap(i) = (theta(2*i-1) + theta(2*i-2) ) / 2
end if
end do
end subroutine guess