!= 螟画焚蜷阪�譛牙柑諤ｧ繧定ｨｭ螳�
!= 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