        subroutine surfce

	implicit none
	include 'param_o.h'
	include 'params'
	include 'pvrbls.comm'
	include 'const.h'
	include 'vrbls.comm'
        include 'masks.comm'
	
	integer::i,j,n
        real,dimension(0:im+1,0:jm+1,nm)::tsfc
	real::psfc
	
        do n=1,nm
	do j=1,jm
	do i=1,im
	    
	    psfc=pt+pd(i,j,n)
            TSFC(I,J,n) =THS(I,J,n)*(PSFC/P1000)**CAPA
       
        enddo
        enddo
        enddo
!+++++++++++++++++++++++
      open(1,file='/home/lucci/GEF/GEF-reta/GEF_tempo/scratchout/post/tmpsfc.dat',form='unformatted')
	write(1)tsfc
      
      write(1)tshltr
      write(1)qshltr
      write(1)plm


	write(1)sfclhx   !!!!!!!!!!!!!!!!DRAGAN
	write(1)sfcshx
    write(1)qwbs
    write(1)twbs        
	
	write(1)grnflx
	write(1)vegfrc
        write(1)IVGTYP
        write(1)ISLTYP
        write(1)glat
        write(1)glon
    write(1)sm	
!	write(1)htm 
!	write(1)vtm
	write(1)sice
	write(1)z0
        write(1)omgalf
	write(1)albedo
       
        write(1)albase
        write(1)mxsnal
         
        write(1)czen
        write(1)czmean	
   write(1)fis
   write(1)q10    
   write(1)th10    
   write(1)qz0    
   write(1)thz0   
   
   write(1)u10
   write(1)v10
   write(1)uz0
   write(1)vz0
   write(1)ustar
   
   write(1)ths	
    
   write(1)q2    
   write(1)tcucn    
   write(1)train    
   write(1)div  
   write(1)rtop 
      close(1)
!++++++++++++++++++++	
      open(2,file='/home/lucci/GEF/GEF-reta/GEF_tempo/scratchout/post/sw_rdtn.dat',form='unformatted')
	write(2)RSWIN
	write(2)RSWOUT
	write(2)RSWTOA   !!!!!!!!!!!!!!!!DRAGAN
	write(2)ASWIN
	write(2)ASWOUT
	
	write(2)ASWTOA
	write(2)rswnet
	write(2)RSWTT
	
      close(2)
	
!++++++++++++++++++++++
      open(3,file='/home/lucci/GEF/GEF-reta/GEF_tempo/scratchout/post/lw_rdtn.dat',form='unformatted')
	write(3)RLWIN
	write(3)RLWOUT
	write(3)RLWTOA   !!!!!!!!!!!!!!!!DRAGAN
	write(3)ALWIN
	write(3)ALWOUT
	
	write(3)ALWTOA
	write(3)rlwnet
	write(3)RLWTT
        write(3)epsr	
      write(3)radot   
      write(3)sigt4 
     
      close(3)

!+++++++++++++++++++++++	
      open(4,file='/home/lucci/GEF/GEF-reta/GEF_tempo/scratchout/post/clouds.dat',form='unformatted')
	write(4)CUPPT
	write(4)cfracl
	write(4)cfracm   !!!!!!!!!!!!!!!!DRAGAN
	write(4)cfrach
        write(4)acfrcv
        write(4)acfrst
!    write(4)f_ice
!    write(4)f_rain
!    write(4)f_RimeF
    
        write(4)cnvtop
        write(4)cnvbot
!        write(4)htop
!        write(4)hbot
      close(4)
!+++++++++++++++++++++++	
      open(5,file='/home/lucci/GEF/GEF-reta/GEF_tempo/scratchout/post/precANDsoil.dat',form='unformatted')
	write(5)acprec
	write(5)cuprec
	write(5)aprec   !!!!!!!!!!!!!!!!DRAGAN
	write(5)acsnow
	
        write(5)acsnom	
	write(5)prec
	
	write(5)stc(:,:,:,1)
	write(5)stc(:,:,:,4)
	write(5)smc(:,:,:,1)
	write(5)smc(:,:,:,4)
	
	write(5)SMSTAV
	write(5)BGROFF
	write(5)SSROFF
        write(5)cmc
        write(5)potevp
        write(5)potflx
      write(5)sfcevp
      write(5)subshx
      write(5)snopcx
    
      write(5)si
      write(5)sno
     	 
      write(5)smstot
      write(5)soiltb  !!!!   
!     write(5)tg      !!!!
      write(5)sr 
      write(5)akhs
      write(5)akms
     	
	
		
      close(5)
!++++++++++++++++++++++
       

      end subroutine surfce
