C********

      subroutine write_lcc
C
c Output lagged wind response coeficent estimates.  Coeficients can be 
c used for forecasting boundary elevation. 
c
c
c Format of the lcc
c
      INCLUDE 'CASCO.DIM'
      include 'deltabcs.h'
      include 'mesh.h' 
      include 'misc.h'
      include 'wind.h' 
C local variables
      character*132 filename 
      integer i, k,j
      integer lun
      integer istart,iend
      integer iday, imonth, iyear
C
      integer nelev_bcs
      real*8 tmp(NseriesDim)

      nr = nelev_bcs()
      write(*,*)'write_lcc: write final lagged coeficients to a file '
      write(*,*)'Enter file name for final lagged coeficients(none)'
      read(*,'(a)')filename
      
      if(filename(1:4).ne.'none')then
	  lun = 51
	  open(lun,file=filename,status='unknown')

C calculate the start time in DD MM YY format
	  call DMY(iday,imonth,iyear,kdbc(1))
          call cstring(meshname,istart,iend)
	  write(lun,'(a)')meshname(istart:iend)
          write(lun,'(a)')'lagged correlation coeficients'
	  write(lun,*)nlags, delttbc 
	  write(lun,*)nr
	  write(lun,*)w_nseries
	  
          do k = 0, nlags-1
           j=k+1
	   do i = 1, nr
            do L=1,w_nseries
	     L0=(L-1)*Nlags
	     tmp(L)=dbcA_BEST(i,j+L0)
	    enddo
	    write(lun,77) k,i,lrvs(i),tmp(1:w_nseries)
	   enddo
	  enddo


	  close(lun)
      endif
 77   FORMAT(3i6,2E12.4)
      RETURN 
      END
