!= å¤‰æ•°åã®æœ‰åŠ¹æ€§ã‚’è¨å®š
!= Set validation to variable names
!
! Authors::   Yasuhiro MORIKAWA
! Version::   $Id: hstnmlinfosetvalidname.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 HstNmlInfoSetValidName( gthstnml, &
    & name, &
    & err )
    !
    ! å¤‰æ•°åã®æœ‰åŠ¹æ€§ã‚’è¨å®š.
    !
    ! ç„¡åŠ¹ãªå¤‰æ•°åã‚’æ¤œçŸ¥ã™ã‚‹ãŸã‚, ã“ã®ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã§
    ! æœ‰åŠ¹ãªå¤‰æ•°ã«å¯¾ã—ã¦ã¯æ˜Žç¤ºçš„ã«è¨å®šã‚’è¡Œã„ã¾ã™.
    !
    ! ãªãŠ, ä¸Žãˆã‚‰ã‚ŒãŸ *gthstnml* ãŒ HstNmlInfoCreate ã«ã‚ˆã£ã¦åˆæœŸè¨å®š
    ! ã•ã‚Œã¦ã„ãªã„å ´åˆ, ãƒ—ãƒã‚°ãƒ©ãƒ ã¯ã‚¨ãƒ©ãƒ¼ã‚’ç™ºç”Ÿã•ã›ã¾ã™.
    !
    ! Set validation to variable names.
    !
    ! For detection of invalid variable names,
    ! Set validation to variable names explicitly by this
    ! subroutine.
    !
    ! If *gthstnml* is not initialized by "HstNmlInfoCreate" yet,
    ! error is occurred.
    !
    use gtool_history_nmlinfo_types, only: GTHST_NMLINFO, GTHST_NMLINFO_ENTRY
    use gtool_history_nmlinfo_internal, only: ListSearch, ListNext
    use gtool_history_nmlinfo_internal, only: name_delimiter
    use gtool_history, only: HistoryInitialized
    use dc_trace, only: BeginSub, EndSub
    use dc_string, only: PutLine, Printf, Split, StrInclude, StoA, JoinChar
    use dc_present, only: present_and_not_empty, present_and_true
    use dc_types, only: DP, STRING, TOKEN, STDOUT
    use dc_error, only: StoreError, DC_NOERR, DC_ENOTINIT, DC_EARGLACK, DC_ENOENTRY
    implicit none
    type(GTHST_NMLINFO), intent(in):: gthstnml
    character(*), intent(in):: name
                              ! æœ‰åŠ¹ã§ã‚ã‚‹ã“ã¨ã‚’è¨å®šã™ã‚‹å¤‰æ•°å.
                              !
                              ! "Data1,Data2" ã®ã‚ˆã†ã«ã‚«ãƒ³ãƒžã§åŒºåˆ‡ã£ã¦è¤‡æ•°
                              ! ã®å¤‰æ•°ã‚’æŒ‡å®šã™ã‚‹ã“ã¨ã‚‚å¯èƒ½ã§ã™.
                              !
                              ! A variable name that is set validation.
                              !
                              ! Multiple variables can be specified
                              ! as "Data1,Data2" too. Delimiter is comma.
    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
    type(GTHST_NMLINFO_ENTRY), pointer:: hptr =>null()
    character(TOKEN), pointer:: varnames_array(:) =>null()
    integer:: i, vnmax
    integer:: stat
    character(STRING):: cause_c
    character(*), parameter:: subname = 'HstNmlInfoSetValidName'
  continue
    call BeginSub( subname, fmt = '@name=%c', c1 = trim(name) )
    stat = DC_NOERR
    cause_c = ''

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

    !-----------------------------------------------------------------
    !  è¤‡æ•°ã®å¤‰æ•°åã®å–ã‚Šæ‰±ã„
    !  Handle multiple variables
    !-----------------------------------------------------------------
    call Split( str = name, sep = name_delimiter, & ! (in)
      & carray = varnames_array )                   ! (out)
    vnmax = size( varnames_array )

    !-----------------------------------------------------------------
    !  *gthstnml* å†…ã‹ã‚‰, *name* ã«é–¢ã™ã‚‹æƒ…å ±ã‚’æŽ¢æŸ».
    !  Search information correspond to *name* in *gthstnml*
    !-----------------------------------------------------------------
    do i = 1, vnmax
      hptr => gthstnml % gthstnml_list
      call ListSearch( gthstnml_list = hptr, &    ! (inout)
        &              name = varnames_array(i) ) ! (in)
      if ( associated( hptr ) ) then
        hptr % name_invalid = .false.
      end if
    end do

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