       subroutine qu2ll

       implicit none
       USE  mod_extra
       include 'param_o.h'
!!       include 'extra.comm'

!!JNT       real, dimension(0:im+1,0:jm+1,nm,lsm)::fsl,usl,vsl,ull,vll,qsl,tsl,q2sl
!!JNT       real, dimension(igm,jgm,lsm)::fsl_ll,hgt_ll,usp,vsp,qsl_ll,tsl_ll,q2sl_ll
!!JNT       real, dimension(igm,jgm)::psurf_ll,tsfc_ll,pslp_ll,acprec_ll
!!JNT       real, dimension(0:im+1,0:jm+1,nm)::tsfc,acprec

       real, allocatable, save, dimension(:,:,:,:)::fsl,usl,vsl,ull,vll,qsl,tsl,q2sl
       real, allocatable, save, dimension(:,:,:)::fsl_ll,hgt_ll,usp,vsp,qsl_ll,tsl_ll,q2sl_ll
       real, allocatable, save, dimension(:,:)::psurf_ll,tsfc_ll,pslp_ll,acprec_ll
       real, allocatable, save, dimension(:,:,:)::tsfc,acprec
       logical, save :: FIRST=.true.
       integer::l,i,j,n,k

       if (FIRST) then
          ALLOCATE(fsl(0:im+1,0:jm+1,nm,lsm))
          ALLOCATE(usl(0:im+1,0:jm+1,nm,lsm))
          ALLOCATE(vsl(0:im+1,0:jm+1,nm,lsm))
          ALLOCATE(ull(0:im+1,0:jm+1,nm,lsm))
          ALLOCATE(vll(0:im+1,0:jm+1,nm,lsm))
          ALLOCATE(qsl(0:im+1,0:jm+1,nm,lsm))
          ALLOCATE(tsl(0:im+1,0:jm+1,nm,lsm))
          ALLOCATE(q2sl(0:im+1,0:jm+1,nm,lsm))

          ALLOCATE(fsl_ll(igm,jgm,lsm))
          ALLOCATE(hgt_ll(igm,jgm,lsm))
          ALLOCATE(usp(igm,jgm,lsm))
          ALLOCATE(vsp(igm,jgm,lsm))
          ALLOCATE(qsl_ll(igm,jgm,lsm))
          ALLOCATE(tsl_ll(igm,jgm,lsm))
          ALLOCATE(q2sl_ll(igm,jgm,lsm))

          ALLOCATE(psurf_ll(igm,jgm))
          ALLOCATE(tsfc_ll(igm,jgm))
          ALLOCATE(pslp_ll(igm,jgm))
          ALLOCATE(acprec_ll(igm,jgm))
          ALLOCATE(tsfc(0:im+1,0:jm+1,nm))
          ALLOCATE(acprec(0:im+1,0:jm+1,nm))

          FIRST = .false.
       endif
        open(1,file='tmpfld.dat',form='unformatted')
	do l=1,lsm
	read(1)fsl(:,:,:,l)
	read(1)usl(:,:,:,l)
	read(1)vsl(:,:,:,l)
!	read(1)qsl(:,:,:,l)
	read(1)tsl(:,:,:,l)
	read(1)q2sl(:,:,:,l)
	enddo
	close(1)

        open(1,file='tmpsfc.dat',form='unformatted')
	read(1)tsfc
	read(1)acprec
	close(1)

       if(nm.eq.14)then
        call octa2llH(fsl, fsl_ll, lsm) 
        call octa2llH(qsl, qsl_ll, lsm) 
        call octa2llH(tsl, tsl_ll, lsm) 
        call octa2llH(q2sl, q2sl_ll, lsm) 
	call octa2llH(pint(:,:,:,lp1),psurf_ll,1)
	call octa2llH(pslp,pslp_ll,1)
	call octa2llH(tsfc,tsfc_ll,1)
	call octa2llH(acprec,acprec_ll,1)
        call llwinds_oc(usl, vsl, ull, vll,lsm)
        call bocovs_oc(ull,im,jm,lsm)
        call bocovs_oc(vll,im,jm,lsm)
        call avrv_oc(ull, usl,lsm)
        call avrv_oc(vll, vsl,lsm)
        usl = usl * .25
        vsl = vsl * .25
        do k=1,nm
	  if(k.eq.1.or.k.eq.2.or.k.eq.7.or.k.eq.8.or.k.eq.9  &
               .or.k.eq.12)then
              usl(1 ,1 ,k,:)=usl(1 ,1 ,k,:)*4./3.
              vsl(1 ,1 ,k,:)=vsl(1 ,1 ,k,:)*4./3.
          endif

	  if(k.eq.1.or.k.eq.4.or.k.eq.6.or.k.eq.7.or.k.eq.11  &
                .or.k.eq.14)then
             usl(im,1 ,k,:)=usl(im,1 ,k,:)*4./3.
             vsl(im,1 ,k,:)=vsl(im,1 ,k,:)*4./3.
          endif

	  if(k.eq.2.or.k.eq.5.or.k.eq.6.or.k.eq.9.or.k.eq.13  &
              .or.k.eq.14)then
             usl(1 ,jm,k,:)=usl(1 ,jm,k,:)*4./3.
             vsl(1 ,jm,k,:)=vsl(1 ,jm,k,:)*4./3.
          endif

	  if(k.eq.4.or.k.eq.5.or.k.eq.8.or.k.eq.11.or.k.eq.12  &
              .or.k.eq.13)then
             usl(im,jm,k,:)=usl(im,jm,k,:)*4./3.
             vsl(im,jm,k,:)=vsl(im,jm,k,:)*4./3.
           endif
        enddo
         
        call octa2llH(usl, usp, lsm) 
        call octa2llH(vsl, vsp, lsm) 

       else if(nm.eq.6)then
        call cube2llH(fsl, fsl_ll, lsm) 
        call cube2llH(qsl, qsl_ll, lsm) 
        call cube2llH(tsl, tsl_ll, lsm) 
        call cube2llH(q2sl, q2sl_ll, lsm) 
	call cube2llH(pint(:,:,:,lp1),psurf_ll,1)
	call cube2llH(pslp,pslp_ll,1)
	call cube2llH(tsfc,tsfc_ll,1)
	call cube2llH(acprec,acprec_ll,1)
        call llwinds(usl, vsl, ull, vll,lsm)
        call bocovs(ull,im,jm,lsm)
        call bocovs(vll,im,jm,lsm)
        call avrv(ull, usl,lsm)
        call avrv(vll, vsl,lsm)
        usl = usl * .25
        vsl = vsl * .25
        do k=1,nm
             usl(1 ,1 ,k,:)=usl(1 ,1 ,k,:)*4./3.
             vsl(1 ,1 ,k,:)=vsl(1 ,1 ,k,:)*4./3.
             usl(im,1 ,k,:)=usl(im,1 ,k,:)*4./3.
             vsl(im,1 ,k,:)=vsl(im,1 ,k,:)*4./3.
             usl(1 ,jm,k,:)=usl(1 ,jm,k,:)*4./3.
             vsl(1 ,jm,k,:)=vsl(1 ,jm,k,:)*4./3.
             usl(im,jm,k,:)=usl(im,jm,k,:)*4./3.
             vsl(im,jm,k,:)=vsl(im,jm,k,:)*4./3.
        enddo
         
        call cube2llH(usl, usp, lsm) 
        call cube2llH(vsl, vsp, lsm) 
       endif

       hgt_ll=fsl_ll/9.80616

         write(10)hgt_ll(:,:,10)

!       write(9)pslp_ll
!       write(9)psurf_ll
!       write(9)tsl_ll
!       write(9)qsl_ll
!       write(9)q2sl_ll
!       print *,'tsl_ll,256,128,',tsl_ll(256,128,1)

       do l=1,lsm
!         write(9)usp(:,:,l)
!         write(9)hgt_ll(:,:,l)
       enddo

       print *,'usp,vsp,',usp(1,90,1),vsp(1,90,1)

       do l=1,lsm
!         write(9)vsp(:,:,l)
       enddo

       do l=1,lsm
!         write(9)tsl_ll(:,:,l)
!DRAGAN 17.09.         write(9)q2sl_ll(:,:,l)
       enddo
!
!       write(9)acprec_ll*1000

!       print *,pslp_ll(261,110)


       end subroutine qu2ll
