      subroutine qgtemp(tqg)

      include 'qg_par.inc'

      common /vert/ rho0, tsurf, xc(k01), salsur, eta(k01)
      common /threed/ hz(k0), scsig, sigz(k01), eigval(k0), ainv(k0,k0),
     +                amat(k0,k0)
      common/fields/vort(mn0,k0),stream(mn0,k0),prvjac(mn0,k0),
     +     topden(mn0),botden(mn0),relief(mn0),prvtop(mn0),
     +     prvbot(mn0),topfct(k0),botfct(k0),pvort(mn0)

      common/parm/kz,m,mm1,mm2,mp1,msq,tim,tmax,tstart,hy,rea,dt,
     +   xbasin,yy(mx0),icalc,kzp1,kzm1,iftop,ifbot,iftvv,ifrel,theta,
     +   ifsbl,ifeva

      common /extpar/ rlat0,rlng0,t0,v0,dhor,ht,time0,r0,f0star

      dimension tqg(k0),tbg(k0),spsiz(k0+1)

      ip = msq / 2

      scale = scsig * v0 * ht / (f0star * dhor)

      spsiz(1)    = topden(ip) / scsig
      spsiz(kz+1) = botden(ip) / scsig

      tbg(1)   = tsurf - xc(1) * (0.5 * hz(1) * ht)

      do 1 k=2,kz
         spsiz(k) = sigz(k) * (stream(ip,k-1) - stream(ip,k)) / 
     .                        (0.5 * (hz(k-1) + hz(k)))
         tbg(k) = tbg(k-1) - xc(k) * (0.5 * (hz(k-1) + hz(k)) * ht)
  1    continue

      do 2 k=1,kz
         tpert = scale * 0.5 * (xc(k) * spsiz(k) + xc(k+1) * spsiz(k+1))
         tqg(k) = tbg(k) + tpert
  2    continue

      return
      end
