program main

  use vtype_module

  use fi_module

  use ni3_module

  use ac_merge, only :        &
    & ACMergeWaveNumber     , &
    & ACMergeVerticalDomain , &
    & ACMergeVerticalDomain2

  implicit none


  character(extstr) :: CtlFN  = 'merge.conf'

  integer           :: iostat

  integer(i4b)              :: FileUnit

  character(len=extstr)     :: InputFileName0
  character(len=extstr)     :: OutputFileName

  integer :: NProcs


  namelist /file_nml/ &
    & NProcs, &
    & InputFileName0, &
    & OutputFileName


  NProcs   = 0
  InputFileName0 = 'out/data.nc'
  OutputFileName = 'out/data.nc'


  ! Read a namelist file

  call fi_open( CtlFN, "read", FileUnit )
  !
  rewind( FileUnit )
  read( FileUnit, nml = file_nml, iostat = iostat )
  if ( iostat > 0 ) then
    stop 'Namelist in file_nml is something wrong.'
  end if
  write( 6, nml = file_nml )
  !
  close( FileUnit )


  if ( .false. ) then
    write( 6, * ) 'Merge wavenumbers'
    call ACMergeWaveNumber( &
      & NProcs, InputFileName0, OutputFileName &
      & )
  else
    write( 6, * ) 'Merge vertical domain'
!!$    call ACMergeVerticalDomain( &
!!$      & NProcs, InputFileName0, OutputFileName &
!!$      & )
    call ACMergeVerticalDomain2( &
      & NProcs, InputFileName0, OutputFileName &
      & )
  end if

  write( 6, * ) 'Finish'


end program main
