!= コマンドライン引数解析処理
!
!= Command line option parser
!
! Authors::   Yasuhiro MORIKAWA
! Version::   $Id:  $ 
! Tag Name::  $Name:  $
! Copyright:: Copyright (C) GFD Dennou Club, 2008. All rights reserved.
! License::   See COPYRIGHT[link:../../../COPYRIGHT]
!

module option_parser
  !
  != コマンドライン引数解析処理
  !
  != Command line option parser
  !
  ! <b>Note that Japanese and English are described in parallel.</b>
  !
  ! コマンドライン引数の解析処理を行います. 
  !
  ! Command line options are parsed
  !
  !== Procedures List
  !
  ! OptParseInit  :: コマンドライン引数の解析処理
  ! ------------  :: ------------
  ! OptParseInit  :: Parse of command line options

  ! モジュール引用 ; USE statements
  !

  ! 種別型パラメタ
  ! Kind type parameter
  !
  use dc_types, only: STRING  ! 文字列. Strings. 

  ! 宣言文 ; Declaration statements
  !
  implicit none
  private

  ! 公開手続き
  ! Public procedure
  !
  public:: OptParseInit

  ! 公開変数
  ! Public variables
  !
  logical, save, public:: initialized = .false.
                              ! 初期設定フラグ. 
                              ! Initialization flag
  character(STRING), save, public:: namelist_filename = ''
                              ! NAMELIST ファイルの名称. 
                              ! NAMELIST file name
  logical, save, public:: namelist_flag = .false.
                              ! NAMELIST ファイル指定の有無を示すフラグ. 
                              ! Flag of NAMELIST file specification

  ! 非公開変数
  ! Private variables
  !
  character(*), parameter:: module_name = 'option_parser'
                              ! モジュールの名称. 
                              ! Module name
  character(*), parameter:: version = &
    & '$Name:  $' // &
    & '$Id: $'
                              ! モジュールのバージョン
                              ! Module version

  ! INTERFACE 文 ; INTERFACE statements
  !
  interface OptParseInit
    module procedure OptParseInit
  end interface

contains

  subroutine OptParseInit
    !
    ! option_parser モジュールの初期設定を行います. 
    !
    ! Initialize "option_parser" module. 
    !

    ! モジュール引用 ; USE statements
    !

    ! 文字列操作
    ! Character handling
    !
    use dc_string, only: StoA

    ! コマンドライン引数処理下請け
    ! Command line option parser subcontractor
    !
    use dc_args, only: ARGS, &
      & DCArgsOpen,  DCArgsHelpMsg, DCArgsOption, &
      & DCArgsDebug, DCArgsHelp,    DCArgsStrict, DCArgsClose

    ! 宣言文 ; Declaration statements
    !

    type(ARGS):: arg          ! コマンドライン引数. 
                              ! Command line options

    ! 実行文 ; Executable statement
    !

    if ( initialized ) return
    call InitCheck

    call DCArgsOpen( arg )               ! (out)

    call DCArgsHelpMsg( arg, &           ! (inout)
      & category = 'Title', &            ! (in)
      & msg = 'dcpam main program' )     ! (in)
    call DCArgsHelpMsg( arg, &           ! (inout)
      & category = 'Usage', &            ! (in)
      & msg = './dcpam' // &             ! (in)
      &       ' [Options]' )             ! (in)

    call DCArgsOption( arg, &                 ! (inout)
      & options = StoA('-N', '--namelist'), & ! (in)
      & flag = namelist_flag, &               ! (out)
      & value = namelist_filename, &          ! (out)
      & help = "Namelist filename")           ! (in)

    call DCArgsDebug( arg )  ! (inout)
    call DCArgsHelp( arg )   ! (inout)
    call DCArgsStrict( arg ) ! (inout)

    call DCArgsClose( arg )  ! (inout)

    initialized = .true.
  end subroutine OptParseInit

  subroutine InitCheck
    !
    ! 依存モジュールの初期化チェック
    !
    ! Check initialization of dependency modules

    ! 実行文 ; Executable statement
    !


  end subroutine InitCheck

!!$  subroutine InitDepmod
!!$    !
!!$    ! 依存モジュールの初期化
!!$    !
!!$    ! Initialize dependency modules
!!$
!!$    ! 実行文 ; Executable statement
!!$    !
!!$
!!$  end subroutine InitDepmod

end module option_parser
