program main

  use vtype_module
  use test03_mtckd_wrapper

  implicit none


  integer :: MTCKD_ipr
  integer :: MTCKD_ipu

  integer :: MTCKD_jrad

  real(DP) :: MTCKD_pave
  real(DP) :: MTCKD_tave
  real(DP) :: MTCKD_vmrh2o
  real(DP) :: MTCKD_xlength

  real(DP) :: MTCKD_VMRN2
  real(DP) :: MTCKD_VMRO2
  real(DP) :: MTCKD_VMRCO2
  real(DP) :: MTCKD_VMRO3
  real(DP) :: MTCKD_VMROTHERS

  real(DP) :: MTCKD_v1abs
  real(DP) :: MTCKD_v2abs
  real(DP) :: MTCKD_dvabs

  integer , parameter :: MTCKD_arraysize = 5050
  real(DP) :: MTCKD_a_absrb (MTCKD_arraysize)
  real(DP) :: MTCKD_a_radfld(MTCKD_arraysize)
  real(DP) :: MTCKD_a_csh2o (MTCKD_arraysize)
  real(DP) :: MTCKD_a_cfh2o (MTCKD_arraysize)
  integer  :: MTCKD_nptabs
  integer  :: MTCKD_npth
  real(DP) :: MTCKD_v1h
  real(DP) :: MTCKD_dvh

  logical :: MTCKD_Flag_co2
  logical :: MTCKD_Flag_o3
  logical :: MTCKD_Flag_o2
  logical :: MTCKD_Flag_n2
  logical :: MTCKD_Flag_rayl

  real(DP) :: vi
  real(DP) :: radfld
  real(DP) :: csh2or
  real(DP) :: cfh2or

  integer :: i


  print *
  print *,' *** For this program, vmr_h2o is taken ',&
    'with respect to the total column ***'

  MTCKD_ipr = 66
  MTCKD_ipu = 7

  open (MTCKD_ipr,file='CNTNM.OPTDPT')
  open (MTCKD_ipu,file='WATER.COEF')
!
  MTCKD_jrad = 1

  MTCKD_PAVE = 1013.
  MTCKD_TAVE =  296.
  MTCKD_xlength = 1.

  MTCKD_VMRH2O    = 0.01
  MTCKD_VMRN2     = 0.78d0
  MTCKD_VMRO2     = 0.21d0
  MTCKD_VMRCO2    = 345.0d-6
  MTCKD_VMRO3     = 0.0d0
  MTCKD_VMROTHERS = 0.009d0

  MTCKD_Flag_co2  = .true.
  MTCKD_Flag_o3   = .true.
  MTCKD_Flag_o2   = .true.
  MTCKD_Flag_n2   = .true.
  MTCKD_Flag_rayl = .true.

  MTCKD_V1ABS =    0.
  MTCKD_V2ABS = 10000.
  MTCKD_DVABS =    2.

  call call_mtckd( &
    & .true., &
    & MTCKD_ipr, MTCKD_ipu, &
    & MTCKD_jrad, &
    & MTCKD_PAVE, MTCKD_TAVE, MTCKD_VMRH2O, MTCKD_xlength, &
    & MTCKD_VMRCO2, MTCKD_VMRO3, MTCKD_VMRO2, MTCKD_VMRN2, MTCKD_VMROTHERS, &
    & MTCKD_Flag_co2, MTCKD_Flag_o3, MTCKD_Flag_o2, MTCKD_Flag_n2, MTCKD_Flag_rayl, &
    & MTCKD_v1abs, MTCKD_v2abs, MTCKD_dvabs, &
    & MTCKD_arraysize, &
    & MTCKD_a_absrb, MTCKD_a_radfld, MTCKD_a_csh2o, MTCKD_a_cfh2o, &
    & MTCKD_npth, &
    & MTCKD_nptabs, &
    & MTCKD_v1h, MTCKD_dvh &
    & )

  do i = 1, MTCKD_nptabs
    vi = MTCKD_v1abs + real(i-1) * MTCKD_dvabs
100 WRITE (MTCKD_ipr, 910) VI, MTCKD_a_ABSRB(I)
  end do
910 FORMAT(F10.3,1P,E12.3)

  WRITE (7,920) MTCKD_tave
920 FORMAT(//,' self and foreign water vapor continuum coefficients ',/,&
      'for  ',f8.2,'K - ',   //,&
      ' the self-continuum scales as ( Rself/Ro ) ',/,&
      ' the foreign continuum scales as ( (Rtot-Rself)/Ro ) ',/,&
      ' where R is the density rho [ R = (P/Po)*(To/T) ]. ',//,&
      10x,'     without radiation field:  ',&
      10x,'       with radiation field:   ',      /,&
      10x,'      self         foreign     ',&
      10x,'      self         foreign     ',      /,&
      '    cm-1  ',&
      '       1/(cm-1 molec/cm**2)    ',&
      10x,'       1/(molec/cm**2) '        ,//)

  do i=1,MTCKD_npth
    vi=MTCKD_v1h+float(i-1)*MTCKD_dvh
    if (vi.ge.MTCKD_v1abs .and. vi.le.MTCKD_v2abs) then
      radfld= MTCKD_a_radfld(i)
      csh2or= MTCKD_a_csh2o(i) * radfld
      cfh2or= MTCKD_a_cfh2o(i) * radfld
      write (MTCKD_ipu,930) vi, MTCKD_a_csh2o(i), MTCKD_a_cfh2o(i), csh2or, cfh2or
930   format(f10.2, 1p, 2e15.4,10x, 1p, 2e15.4)
    endif
  end do

end program main
