        subroutine link2htfluxice(iperx,npt,nx,ny,iox,xm,ym, tstep, tmonth,
     *                        sst, cldfr, wspd, u, v,
     *                        q, t, rlh, sh, qlw, qa, th, rh, 
     *                        sss, qisw, ppi, qsw, pp, qios, brne,
     *                        hice, cice, thice, tsnw, rlhi, shi, qlwi, qswi)
	include 'comm_amlice.h'
	include 'amlice.h'
	dimension xm(nx), ym(ny), iox(1)
	dimension sst(npt), cldfr(npt), wspd(npt), u(npt), v(npt), 
     *       q(nx,ny), t(nx,ny), rlh(npt), sh(npt), qlw(npt),
     *       qa(nx,ny), th(nx,ny), rh(nx,ny),
     *       sss(npt), qisw(npt), ppi(npt), qsw(npt), pp(npt), 
     *       qios(npt), brne(npt),
     *       hice(npt), cice(npt), thice(npt), tsnw(nx,ny), 
     *       rlhi(nx,ny), shi(nx,ny), qlwi(nx,ny), qswi(nx,ny)
	
	logical FIRST_PBL
	save    FIRST_PBL
	data    FIRST_PBL /.true./

	if ( FIRST_PBL ) then
	   call init_amlice(npt, NX, NY, xm, ym, iox, slat)
	   do j = 1, ny
	      do i = 1, nx
                 tsnw(i,j) = tfreeze
		 lsm_aml(i,j) = 1
		 k = lsm(i,j)
		 if (k.ne.0) then
		    lsm_aml(i,j) = 0
		 endif
	      enddo
	   enddo
	   FIRST_PBL = .false.
	endif
	
	do j = 1, ny
	   do i = 1, nx
	      k = lsm(i,j)
	      if (k.ne.0) then
		 aml_cice(i,j) = cice(k)
		 aml_hice(i,j) = hice(k)
		 aml_thice(i,j) = thice(k)
		 aml_sst(i,j) = sst(k) + 273.15
		 aml_cldf(i,j) = cldfr(k)
		 aml_wspd(i,j) = wspd(k)
		 aml_u(i,j) = u(k)
		 aml_v(i,j) = v(k)
		 aml_sss(i,j) = sss(k)
		 aml_qisw(i,j) = qisw(k)
		 aml_ppi(i,j) = ppi(k)
	      endif
	   enddo
	enddo

	call htfluxice(nx,ny,nx,ny,lsm_aml,dxd,dyd,tstep,tmonth,
     +         aml_sst,aml_cldf,aml_wspd,aml_u,aml_v,q,t,
     +         aml_rlh,aml_sh,aml_qlw,aml_qsw,aml_pp,qa,th,rh,
     +         aml_sss,aml_qisw,aml_ppi,aml_hice,aml_cice,aml_thice,
     +         tsnw,aml_qios,aml_brne,rlhi,shi,qlwi,qswi,
     +         rlc0ice,cpc0ice,qlwice1,qlwice2,iperx)

c   call ice_pressure and forcing  here

	do j = 1, ny
	   do i = 1, nx
	      k = lsm(i,j)
	      if (k.ne.0) then
		 cice(k) = aml_cice(i,j)
		 hice(k) = aml_hice(i,j)
		 thice(k) = aml_thice(i,j)
		 rlh(k) = aml_rlh(i,j)
		 sh(k) = aml_sh(i,j) 
		 qlw(k) = aml_qlw(i,j) 
		 qsw(k) = aml_qsw(i,j) 
		 pp(k) = aml_pp(i,j) 
		 qios(k) = aml_qios(i,j)
		 brne(k) = aml_brne(i,j)
	      endif
	   enddo
	enddo
	
	return
	end
         
c---------------------------------------------------------------------------
	subroutine init_amlice(npt, NX, NY, xm, ym, iox, slat)
c---------------------------------------------------------------------------
	dimension iox(npt), lsm1d(1), xm(nx), ym(ny)
	pointer (p_lsm1d, lsm1d)
	include 'comm_amlice.h'
	
	nxy = nx*ny
	call mem_alloc (p_aml_cice,  nxy, 2, 'aml_cice')
	call mem_alloc (p_aml_hice,  nxy, 2, 'aml_hice')
	call mem_alloc (p_aml_thice,  nxy, 2, 'aml_thice')

	call mem_alloc (p_aml_sst,  nxy, 2, 'aml_sst')
	call mem_alloc (p_aml_sss,  nxy, 2, 'aml_sss')
	call mem_alloc (p_aml_u,  nxy, 2, 'aml_u')
	call mem_alloc (p_aml_v,  nxy, 2, 'aml_v')
	call mem_alloc (p_aml_cldf,  nxy, 2, 'aml_cldf')
	call mem_alloc (p_aml_wspd,  nxy, 2, 'aml_wspd')
	call mem_alloc (p_aml_qisw,  nxy, 2, 'aml_qisw')
	call mem_alloc (p_aml_ppi,  nxy, 2, 'aml_ppi')
	call mem_alloc (p_aml_rlh,  nxy, 2, 'aml_rlh')
	call mem_alloc (p_aml_sh,  nxy, 2, 'aml_sh')
	call mem_alloc (p_aml_qlw,  nxy, 2, 'aml_qlw')
	call mem_alloc (p_aml_qsw,  nxy, 2, 'aml_qsw')
	call mem_alloc (p_aml_pp,  nxy, 2, 'aml_pp')
	call mem_alloc (p_aml_qios,  nxy, 2, 'aml_qios')
	call mem_alloc (p_aml_brne,  nxy, 2, 'aml_brne')
	
	call mem_alloc (p_lsm,      nxy,  1, 'lsm')
	call mem_alloc (p_lsm_aml,  nxy,  1, 'lsm_aml')
	call mem_alloc (p_dxd,      nxy,  1, 'dxd')
	call mem_alloc (p_dyd,       ny,  1, 'dyd')

	call mem_alloc (p_rlc0ice,   nxy,  2, 'rlc0ice')
	call mem_alloc (p_cpc0ice,   nxy,  2, 'cpc0ice')
	call mem_alloc (p_qlwice1,   nxy,  2, 'qlwice1')
	call mem_alloc (p_qlwice2,   nxy,  2, 'qlwice2')

	slat = ym(1)
	do j = 1, ny-1
	   dyd(j) = ym(j+1) - ym(j)
	   do i = 2, nx
	      dxd(i,j) = xm(i) - xm(i-1)
	   enddo
	   dxd(1,j) = dxd(2,j)
	enddo

        j = ny
	dyd(j) = dyd(j-1)
        do i = 2, nx
           dxd(i,j) = xm(i) - xm(i-1)
        enddo
        dxd(1,j) = dxd(2,j)
	
	p_lsm1d = p_lsm
	do i = 1, npt
	   lsm1d(iox(i)) = i
	enddo
	
	return
	end

