program kolum ,24
use kcnst; use kvar; use kphysmod; use micromod
implicit none
integer navg

call kickoff
call read_restart 
call open_trace(1)
call z_coords !just to be sure 
call mass_coords !just to be sure 

navg=0
do while (time.lt.tstop)
	hite=(1-hite_filter)*F_get_hite3(smoke,2)+hite_filter*hite
	if (gridadapt.ge.2) call grid_adapt
	call exner_to_z 
	call z_coords 
	call calc_mean_rho 
	call tke_to_rho_k 
	call subsidence
	include '../inc/prognosticate.inc'
        fth(1)=sflux
        fqv(1)=qvflux
        !fqv(1)=1.2*1.3e-3*(.01067-qv(1))
	include '../inc/prognosticate2.inc'
	if (tkeon.gt.0) call prog_tke 
	!call clean_up
	call update_time 
        if (radiate.gt.0) call radiation(radtop,radabsorb,radiate)
        th=th+radrate*dt
	if (wetphys.gt.0) call microphysics(wetphys)  
	if (time.ge.timemon) call write_mon
	if (time.ge.timetrace) call write_trace 
	if (time.ge.timehist) call write_hist
        if (time.ge.7200.and.time.lt.10800) then
          navg=navg+1
          if (navg.eq.1) then
	     debugf1=fth 
          else
	     debugf1=(debugf1*(n-1)+fth)/n
          end if
        end if
end do

call write_restart 

contains


subroutine grid_adapt 1,4
	ztop=zf(nf)
	call blgrid_prep 
	dzfdt=0.
	dzfdt=(zfnext-zf)/dt
	call dzfdt_to_dmfdt 
	mf=mf+dt*dmfdt
	dmfold=dmf
	call mass_to_pres_to_exner
	call mass_coords 
end subroutine grid_adapt

end program kolum