!= å‡ºåŠ›ãƒ¢ãƒ¼ãƒ‰ã‹ã‚‰å®šç¾©ãƒ¢ãƒ¼ãƒ‰ã«ç§»è¡Œ
!= Transit from output mode to define mode
!
! Authors::   Yasuhiro MORIKAWA
! Version::   $Id: hstnmlinforedefine.f90,v 1.1 2009-05-11 15:15:14 morikawa Exp $
! Tag Name::  $Name:  $
! Copyright:: Copyright (C) GFD Dennou Club, 2007-2009. All rights reserved.
! License::   See COPYRIGHT[link:../../../COPYRIGHT]
!
  subroutine HstNmlInfoReDefine( gthstnml, err )
    !
    ! å‡ºåŠ›ãƒ¢ãƒ¼ãƒ‰ã‹ã‚‰å®šç¾©ãƒ¢ãƒ¼ãƒ‰ã«æˆ»ã‚Š,
    ! å†ã³æƒ…å ±ã‚’è¨å®šå¯èƒ½ã«ã—ã¾ã™.
    ! HstNmlInfoAssocGTHist ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã‚’å‘¼ã³å‡ºã™å‰ã«ã¯,
    ! å†åº¦ HstNmlInfoEndDefine ã‚’å‘¼ã³å‡ºã—ã¦å®šç¾©ãƒ¢ãƒ¼ãƒ‰ã¸ã¨ç§»è¡Œã—ã¦ãã ã•ã„.
    ! ã“ã®ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã‚’å‘¼ã‚“ã å¾Œã§ãªã‚‰, å†åº¦
    ! HstNmlInfoAdd, HstNmlInfoDelete, HstNmlInfoResetDefault
    ! ã‚’å‘¼ã¶ã“ã¨ãŒå¯èƒ½ã§ã™.
    !
    ! ãªãŠ, ä¸Žãˆã‚‰ã‚ŒãŸ *gthstnml* ãŒ HstNmlInfoCreate ã«ã‚ˆã£ã¦åˆæœŸè¨å®š
    ! ã•ã‚Œã¦ã„ãªã„å ´åˆã«ã‚‚, ãƒ—ãƒã‚°ãƒ©ãƒ ã¯ã‚¨ãƒ©ãƒ¼ã‚’ç™ºç”Ÿã•ã›ã¾ã™.
    !
    ! Return from output mode to define mode,
    ! information can be configured again.
    ! Use "HstNmlInfoEndDefine" again and
    ! transit from define mode to output mode,
    ! before "HstNmlInfoAssocGTHist" is used.
    ! "HstNmlInfoAdd", "HstNmlInfoDelete", "HstNmlInfoResetDefault"
    ! can be are used again after
    ! this subroutine is used.
    !
    ! If *gthstnml* is not initialized by "HstNmlInfoCreate" yet,
    ! error is occurred.
    !
    use gtool_history_nmlinfo_types, only: GTHST_NMLINFO
    use dc_trace, only: BeginSub, EndSub
    use dc_string, only: PutLine, Printf, Split, StrInclude, StoA, JoinChar
    use dc_types, only: DP, STRING, TOKEN, STDOUT
    use dc_hash, only: HASH, DCHashPut, DCHashGet, DCHashRewind, DCHashNext, DCHashNumber
    use dc_error, only: StoreError, DC_NOERR, DC_ENOTINIT, HST_ENOTINDEFINE, HST_EINTFILE, HST_EINDEFINE
    use dc_message, only: MessageNotify
    implicit none
    type(GTHST_NMLINFO), intent(inout):: gthstnml
    logical, intent(out), optional:: err
                              ! ä¾‹å¤–å‡¦ç†ç”¨ãƒ•ãƒ©ã‚°.
                              ! ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆã§ã¯, ã“ã®æ‰‹ç¶šãå†…ã§ã‚¨ãƒ©ãƒ¼ãŒ
                              ! ç”Ÿã˜ãŸå ´åˆ, ãƒ—ãƒã‚°ãƒ©ãƒ ã¯å¼·åˆ¶çµ‚äº†ã—ã¾ã™.
                              ! å¼•æ•° *err* ãŒä¸Žãˆã‚‰ã‚Œã‚‹å ´åˆ,
                              ! ãƒ—ãƒã‚°ãƒ©ãƒ ã¯å¼·åˆ¶çµ‚äº†ã›ãš, ä»£ã‚ã‚Šã«
                              ! *err* ã« .true. ãŒä»£å…¥ã•ã‚Œã¾ã™.
                              !
                              ! Exception handling flag.
                              ! By default, when error occur in
                              ! this procedure, the program aborts.
                              ! If this *err* argument is given,
                              ! .true. is substituted to *err* and
                              ! the program does not abort.

    !-----------------------------------
    !  ä½œæ¥å¤‰æ•°
    !  Work variables
    integer:: stat
    character(STRING):: cause_c
    character(*), parameter:: subname = 'HstNmlInfoReDefine'
  continue
    call BeginSub( subname )
    stat = DC_NOERR
    cause_c = ''

    !-----------------------------------------------------------------
    !  åˆæœŸè¨å®šã®ãƒã‚§ãƒƒã‚¯
    !  Check initialization
    !-----------------------------------------------------------------
    if ( .not. gthstnml % initialized ) then
      stat = DC_ENOTINIT
      cause_c = 'GTHST_NMLINFO'
      goto 999
    end if

    if ( gthstnml % define_mode ) then
      stat = HST_EINDEFINE
      cause_c = 'ReDefine'
      goto 999
    end if

    !-----------------------------------------------------------------
    !  å®šç¾©ãƒ¢ãƒ¼ãƒ‰ã¸ã¨æˆ»ã‚‹
    !  Return to define mode
    !-----------------------------------------------------------------
    gthstnml % define_mode = .true.

    !-----------------------------------------------------------------
    !  çµ‚äº†å‡¦ç†, ä¾‹å¤–å‡¦ç†
    !  Termination and Exception handling
    !-----------------------------------------------------------------
999 continue
    call StoreError( stat, subname, err, cause_c )
    call EndSub( subname )
  end subroutine HstNmlInfoReDefine