C********

      subroutine trial_bcs(casco_iter)
C
      INCLUDE 'CASCO.DIM'
      include 'deltabcs.h'
      include 'errors.h'
      include 'statistics.h' 
      include 'gradcost.h' 
      include 'casco_params.h' 

      integer casco_iter

C local variables
      integer i, k
      real    size, factor
      real    size2
      integer nr

C function
      real    sup_norm2d
      integer nelev_bcs

      nr = nelev_bcs() 

      write(*,*)'TRIAL_BCS: transfer moody inferred bcs to SACO'
      write(*,*)'  number of boundary nodes ', nr

      write(*,*)'  DELTTBC, ntbc', DELTTBC, ntbc


C ntbc is number of time steps in the moody time series output of 
C boundary conditions

      size = sup_norm2d(DomegaDrho,nr,ntbc,NRDIM,NTBCDIM)
      size2 = sup_norm2d(DBC_BEST,nr,ntbc,NRDIM,NTBCDIM)
      write(*,*)'size DomegaDrho, dbc_best ', size, size2
      write(*,*)'trial_bcs:rms',scale_DoDr,size,rms_vel
      if (size.ne.0.)then 
        factor = scale_DoDr/size
      else
	write(*,*)'Congradulations! you have reached bottom'
        factor=0.
      endif  
        write(*,101)casco_iter, size,scale_DoDr,factor
101     format('TRIAL_BCS: ',i3,4(1x,g12.4))
             do k = 1, ntbc
                do i = 1, nr
		   DBC(i,k) = DBC_BEST(i,k) -DomegaDrho(i,k)*factor 
		enddo
	     enddo
             size2 = sup_norm2d(DBC,nr,ntbc,NRDIM,NTBCDIM)
	     write(*,*)'max DBC ', size2
	     write(*,*)'leaving TRIAL_BCS'

      RETURN 
      END


