program boxmodel_coupled_driver

         use active_module
         implicit none

      integer, parameter :: kdim=3
      integer i,j

c     from box_ini_params

      COMMON /fi_state_r/ TOLD, TNOW, TNEW, SOLD, SNOW, SNEW
      type(active) :: TOLD(1 : 3)
      type(active) :: TNOW(1 : 3)
      type(active) :: TNEW(1 : 3)
      type(active) :: SOLD(1 : 3)
      type(active) :: SNOW(1 : 3)
      type(active) :: SNEW(1 : 3)

      common /fi_controls_r/ xx
      type(active) :: xx(1 : 6) 

      external box_model_body
!
! ACTS code
!
        call init_fm_rm(6,6)

        call box_ini_params
        call box_ini_fields
        call setderiv(xx(1),(/1.D0,0.D0,0.D0,0.D0,0.D0,0.D0/))
        call setderiv(xx(2),(/0.D0,1.D0,0.D0,0.D0,0.D0,0.D0/))
        call setderiv(xx(3),(/0.D0,0.D0,1.D0,0.D0,0.D0,0.D0/))
        call setderiv(xx(4),(/0.D0,0.D0,0.D0,1.D0,0.D0,0.D0/))
        call setderiv(xx(5),(/0.D0,0.D0,0.D0,0.D0,1.D0,0.D0/))
        call setderiv(xx(6),(/0.D0,0.D0,0.D0,0.D0,0.D0,1.D0/))
cun IN: gamma_t, tStar, nullforce, uvel, tnow, told
cun OUT: tnew
cun ACTIVE: uvel, tnow, told, tnew
cph
cph        call box_timestep('T',gamma_t,tStar,nullforce,uvel,
cph     + tnow,told,tnew)
        call box_model_body
        print*, "Jacobian (computed by TLM)"
        do j=1,kdim
          write(*,'(6(F6.4,"  "))') getderiv(tnew(j))
        end do
        do j=1,kdim
          write(*,'(6(F6.4,"  "))') getderiv(snew(j))
        end do

cun reverse seeding 
        call init_adjoint

        call set_adjoint(tnew(1),(/1.D0,0.D0,0.D0,0.D0,0.D0,0.D0/))
        call set_adjoint(tnew(2),(/0.D0,1.D0,0.D0,0.D0,0.D0,0.D0/))
        call set_adjoint(tnew(3),(/0.D0,0.D0,1.D0,0.D0,0.D0,0.D0/))
        call set_adjoint(snew(1),(/0.D0,0.D0,0.D0,1.D0,0.D0,0.D0/))
        call set_adjoint(snew(2),(/0.D0,0.D0,0.D0,0.D0,1.D0,0.D0/))
        call set_adjoint(snew(3),(/0.D0,0.D0,0.D0,0.D0,0.D0,1.D0/))

          call adjoint_interpreter
          print*, "transposed Jacobian (computed by ADM)"
          do j=1,2*kdim
            write(*,'(6(F6.4,"  "))') get_adjoint(xx(j))
          end do

	end program boxmodel_coupled_driver

        include "diff.xb.x2w.w2f.pp.f"