program main

  use vtype_module
  use test07_mtckd_wrapper

  implicit none


  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               :: MTCKD_arraysize
  real(DP), allocatable :: MTCKD_a_absrb      (:)
  real(DP), allocatable :: MTCKD_a_absrb_total(:)

  integer  :: MolNum

!!$  logical :: MTCKD_Flag_h2o
!!$  logical :: MTCKD_Flag_co2
!!$  logical :: MTCKD_Flag_o3
!!$  logical :: MTCKD_Flag_o2
!!$  logical :: MTCKD_Flag_n2
!!$  logical :: MTCKD_Flag_rayl

  integer :: MTCKD_fu
  real(DP) :: vi
  integer :: i


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

!
  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_VMRH2O    = 0.01
!!$  MTCKD_VMRN2     = 0.78d0
!!$  MTCKD_VMRO2     = 0.21d0
!!$  MTCKD_VMRCO2    = 0.0d0
!!$  MTCKD_VMRO3     = 0.0d0
!!$  MTCKD_VMROTHERS = 1.0d0 - MTCKD_VMRH2O - MTCKD_VMRN2 - MTCKD_VMRO2 - MTCKD_VMRCO2 - MTCKD_VMRO3

!!$  MTCKD_Flag_h2o  = .true.
!!$  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.

  MTCKD_ArraySize = ( MTCKD_V2ABS - MTCKD_V1ABS ) / MTCKD_DVABS + 1
  allocate( MTCKD_a_absrb      (MTCKD_arraysize) )
  allocate( MTCKD_a_absrb_total(MTCKD_arraysize) )


  MTCKD_a_absrb_total = 0.0d0

  do i = 1, 23
!!$  do i = 1, 1

!!$    select case ( i )
!!$    case ( 1 )
!!$      MolNum = i
!!$!      Flag_N2 = .true.
!!$    case ( 2:3 )
!!$      MolNum = i
!!$    case ( 4 )
!!$      MolNum = 7
!!$    case ( 5 )
!!$      MolNum = -100
!!$    end select

    if ( i == 23 ) then
      MolNum = -100
    else if ( ( ( 4 <= i ) .and. ( i <=  6 ) ) .or. &
      &       ( ( 8 <= i ) .and. ( i <= 21 ) ) ) then
      cycle
    else
      MolNum = i
    end if


    call call_mtckd_wrapper( &
      & MTCKD_PAVE, MTCKD_TAVE, MTCKD_VMRH2O, MTCKD_xlength, &
      & MolNum, &
      & MTCKD_VMRCO2, MTCKD_VMRO3, MTCKD_VMRO2, MTCKD_VMRN2, MTCKD_VMROTHERS, &
      & MTCKD_v1abs, MTCKD_v2abs, MTCKD_dvabs, &
      & MTCKD_arraysize, &
      & MTCKD_a_absrb &
      & )

    MTCKD_a_absrb_total = MTCKD_a_absrb_total + MTCKD_a_absrb
  end do

  MTCKD_a_absrb = MTCKD_a_absrb_total


  MTCKD_fu = 60
  open( MTCKD_fu, file='CNTNM.OPTDPT-mod' )
  do i = 1, MTCKD_arraysize
    vi = MTCKD_v1abs + real(i-1) * MTCKD_dvabs
100 WRITE (MTCKD_fu, 510) VI, MTCKD_a_ABSRB(I)
  end do
510 FORMAT(F10.3,1P,E12.3)
  close( MTCKD_fu )

end program main
