!= "GTHST_NMLINFO" å¤‰æ•°ã®å‡ºåŠ›æƒ…å ±ã‚’å•ã„åˆã‚ã›
!= Inquire output information of a "GTHST_NMLINFO" variable
!
! Authors::   Yasuhiro MORIKAWA
! Version::   $Id: hstnmlinfoinquire.f90,v 1.2 2009-10-10 10:59:00 morikawa Exp $
! Tag Name::  $Name:  $
! Copyright:: Copyright (C) GFD Dennou Club, 2007-2009. All rights reserved.
! License::   See COPYRIGHT[link:../../../COPYRIGHT]
!
  subroutine HstNmlInfoInquire( gthstnml, &
    & name, &
    & file, &
    & interval_value, &
    & interval_unit, &
    & precision, &
    & time_average, average, &
    & fileprefix, &
    & origin_value, origin_unit, &
    & terminus_value, terminus_unit, &
    & slice_start, slice_end, slice_stride, &
    & space_average, &
    & newfile_intvalue, newfile_intunit, &
    & err )
    !
    ! å¤‰æ•°ã®å‡ºåŠ›æƒ…å ±ã‚’å•ã„åˆã‚ã›ã¾ã™.
    !
    ! ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆå€¤ã‚’å–å¾—ã™ã‚‹ã«ã¯, *name* ã‚’ä¸Žãˆãªã„ã‹, ã¾ãŸã¯
    ! *name* ã«ç©ºç™½ã‚’ä¸Žãˆã¦ãã ã•ã„.
    !
    ! *name* ã«é–¢ã™ã‚‹ãƒ‡ãƒ¼ã‚¿ãŒå˜åœ¨ã—ãªã„å ´åˆ, ã‚¨ãƒ©ãƒ¼ã‚’ç™ºç”Ÿã•ã›ã¾ã™.
    !
    ! ãªãŠ, ä¸Žãˆã‚‰ã‚ŒãŸ *gthstnml* ãŒ HstNmlInfoCreate ã«ã‚ˆã£ã¦åˆæœŸè¨å®š
    ! ã•ã‚Œã¦ã„ãªã„å ´åˆ, ãƒ—ãƒã‚°ãƒ©ãƒ ã¯ã‚¨ãƒ©ãƒ¼ã‚’ç™ºç”Ÿã•ã›ã¾ã™.
    !
    ! Inquire output information of a variable.
    !
    ! If data correspond to *name* is not found,
    ! error is occurred.
    !
    ! 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
    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), optional:: name
                              ! å¤‰æ•°å.
                              ! å…ˆé ã®ç©ºç™½ã¯ç„¡è¦–ã•ã‚Œã¾ã™.
                              !
                              ! Variable identifier.
                              ! Blanks at the head of the name are ignored.
    character(*), intent(out), optional:: file
                              ! ãƒ’ã‚¹ãƒˆãƒªãƒ‡ãƒ¼ã‚¿ã®ãƒ•ã‚¡ã‚¤ãƒ«å.
                              ! History data filenames
    real(DP), intent(out), optional:: interval_value
                              ! ãƒ’ã‚¹ãƒˆãƒªãƒ‡ãƒ¼ã‚¿ã®å‡ºåŠ›é–“éš”ã®æ•°å€¤.
                              ! è² ã®å€¤ã‚’ä¸Žãˆã‚‹ã¨, å‡ºåŠ›ã‚’æŠ‘æ¢ã—ã¾ã™.
                              !
                              ! Numerical value for interval of history data output.
                              ! Negative values suppresses output.
    character(*), intent(out), optional:: interval_unit
                              ! ãƒ’ã‚¹ãƒˆãƒªãƒ‡ãƒ¼ã‚¿ã®å‡ºåŠ›é–“éš”ã®å˜ä½.
                              ! Unit for interval of history data output
    character(*), intent(out), optional:: precision
                              ! ãƒ’ã‚¹ãƒˆãƒªãƒ‡ãƒ¼ã‚¿ã®ç²¾åº¦.
                              ! Precision of history data
    logical, intent(out), optional:: time_average
                              ! å‡ºåŠ›ãƒ‡ãƒ¼ã‚¿ã®æ™‚é–“å¹³å‡åŒ–ãƒ•ãƒ©ã‚°.
                              ! Flag for time average of output data.
    logical, intent(out), optional:: average
                              ! time_average ã®æ—§ç‰ˆ.
                              ! Old version of "time_average"
    character(*), intent(out), optional:: fileprefix
                              ! ãƒ’ã‚¹ãƒˆãƒªãƒ‡ãƒ¼ã‚¿ã®ãƒ•ã‚¡ã‚¤ãƒ«åã®æŽ¥é è©ž.
                              ! Prefixes of history data filenames
    real(DP), intent(out), optional:: origin_value
                              ! å‡ºåŠ›é–‹å§‹æ™‚åˆ».
                              ! Start time of output.
    character(*), intent(out), optional:: origin_unit
                              ! å‡ºåŠ›é–‹å§‹æ™‚åˆ»ã®å˜ä½.
                              ! Unit of start time of output.
    real(DP), intent(out), optional:: terminus_value
                              ! å‡ºåŠ›çµ‚äº†æ™‚åˆ».
                              ! End time of output.
    character(*), intent(out), optional:: terminus_unit
                              ! å‡ºåŠ›çµ‚äº†æ™‚åˆ»ã®å˜ä½.
                              ! Unit of end time of output.
    integer, intent(out), optional:: slice_start(:)
                              ! ç©ºé–“æ–¹å‘ã®é–‹å§‹ç‚¹.
                              ! Start points of spaces.
    integer, intent(out), optional:: slice_end(:)
                              ! ç©ºé–“æ–¹å‘ã®çµ‚äº†ç‚¹.
                              ! End points of spaces.
    integer, intent(out), optional:: slice_stride(:)
                              ! ç©ºé–“æ–¹å‘ã®åˆ»ã¿å¹….
                              ! Strides of spaces.
    logical, intent(out), optional:: space_average(:)
                              ! å¹³å‡åŒ–ã®ãƒ•ãƒ©ã‚°.
                              ! Flag of average.
    integer, intent(out), optional:: newfile_intvalue
                              ! ãƒ•ã‚¡ã‚¤ãƒ«åˆ†å‰²æ™‚é–“é–“éš”.
                              ! Interval of time of separation of a file.
    character(*), intent(out), optional:: newfile_intunit
                              ! ãƒ•ã‚¡ã‚¤ãƒ«åˆ†å‰²æ™‚é–“é–“éš”ã®å˜ä½.
                              ! Unit of interval of time of separation of a file.

    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(STRING):: name_work
    integer:: stat, ary_size
    character(STRING):: cause_c
    character(*), parameter:: subname = 'HstNmlInfoInquire'
  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

    !-----------------------------------------------------------------
    !  *gthstnml* å†…ã‹ã‚‰, *name* ã«é–¢ã™ã‚‹æƒ…å ±ã‚’æŽ¢æŸ».
    !  Search information correspond to *name* in *gthstnml*
    !-----------------------------------------------------------------
    if ( present(name) ) then
      name_work = name
    else
      name_work = ''
    end if
    hptr => gthstnml % gthstnml_list
    call ListSearch( gthstnml_list = hptr, & ! (inout)
      &              name = name_work )      ! (in)

    if ( .not. associated( hptr ) ) then
      stat = DC_ENOENTRY
      cause_c = adjustl( name_work )
      goto 999
    end if

    if ( hptr % name == '' ) then
      if ( present(file)           ) file           = ''
    else
      if ( present(file)           ) file           = trim( hptr % fileprefix ) // hptr % file
    end if
    if ( present(interval_value) ) interval_value = hptr % interval_value
    if ( present(interval_unit)  ) interval_unit  = hptr % interval_unit
    if ( present(precision)      ) precision      = hptr % precision
    if ( present(average)        ) average        = hptr % time_average
    if ( present(time_average)   ) time_average   = hptr % time_average
    if ( present(fileprefix)     ) fileprefix     = hptr % fileprefix

    if ( present(origin_value    ) ) origin_value     = hptr % origin_value
    if ( present(origin_unit     ) ) origin_unit      = hptr % origin_unit
    if ( present(terminus_value  ) ) terminus_value   = hptr % terminus_value
    if ( present(terminus_unit   ) ) terminus_unit    = hptr % terminus_unit
    if ( present(slice_start     ) ) then
      ary_size = size(slice_start)
      slice_start  = hptr % slice_start(1:ary_size)
    end if
    if ( present(slice_end     ) ) then
      ary_size = size(slice_end)
      slice_end  = hptr % slice_end(1:ary_size)
    end if
    if ( present(slice_stride     ) ) then
      ary_size = size(slice_stride)
      slice_stride  = hptr % slice_stride(1:ary_size)
    end if
    if ( present(space_average     ) ) then
      ary_size = size(space_average)
      space_average  = hptr % space_average(1:ary_size)
    end if
    if ( present(newfile_intvalue) ) newfile_intvalue = hptr % newfile_intvalue
    if ( present(newfile_intunit ) ) newfile_intunit  = hptr % newfile_intunit

    nullify( hptr )

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