!= å˜ä½ã‚’è¡¨ã™æ–‡å—åˆ—ã®è§£æž
!= Parse strings that mean units
!
! Authors::   Yasuhiro MORIKAWA
! Version::   $Id: dcdatetimeparseunits.f90,v 1.1 2009-05-25 10:01:34 morikawa Exp $
! Tag Name::  $Name:  $
! Copyright:: Copyright (C) GFD Dennou Club, 2000-2005. All rights reserved.
! License::   See COPYRIGHT[link:../../COPYRIGHT]
!
  function DCDateTimeParseUnits(str) result(symbol)
    !
    ! å¼•æ•° *str* ã«ä¸Žãˆã‚‰ã‚ŒãŸæ–‡å—åˆ—ã‚’è§£é‡ˆã—, æ—¥æ™‚ã®å˜ä½ã‚’ç¤ºã™
    ! ã‚·ãƒ³ãƒœãƒ«ã‚’è¿”ã—ã¾ã™. ãã‚Œãžã‚Œä»¥ä¸‹ã®æ–‡å—åˆ—ãŒæ—¥æ™‚ã®å˜ä½ã¨ã—ã¦è§£é‡ˆã•ã‚Œã¾ã™.
    ! å¤§æ–‡å—ã¨å°æ–‡å—ã¯åŒºåˆ¥ã•ã‚Œã¾ã›ã‚“.
    !
    ! å¹´         :: dc_date_types#UNIT_YEAR
    ! æœˆ         :: dc_date_types#UNIT_MONTH
    ! æ—¥         :: dc_date_types#UNIT_DAY
    ! æ™‚         :: dc_date_types#UNIT_HOUR
    ! åˆ†         :: dc_date_types#UNIT_MIN
    ! ç§’         :: dc_date_types#UNIT_SEC
    ! ç„¡æ¬¡å…ƒæ™‚é–“ :: dc_date_types#UNIT_NONDIM
    !
    ! è¿”ã‚‹ã‚·ãƒ³ãƒœãƒ« (æ•´æ•°åž‹) ã¯ä»¥ä¸‹ã®é€šã‚Šã§ã™.
    !
    ! å¹´         :: dc_date_types#UNIT_SYMBOL_YEAR
    ! æœˆ         :: dc_date_types#UNIT_SYMBOL_MONTH
    ! æ—¥         :: dc_date_types#UNIT_SYMBOL_DAY
    ! æ™‚         :: dc_date_types#UNIT_SYMBOL_HOUR
    ! åˆ†         :: dc_date_types#UNIT_SYMBOL_MIN
    ! ç§’         :: dc_date_types#UNIT_SYMBOL_SEC
    ! ç„¡æ¬¡å…ƒæ™‚é–“ :: dc_date_types#UNIT_SYMBOL_NONDIM
    !
    ! ã“ã‚Œã‚‰ã«è©²å½“ã—ãªã„æ–‡å—åˆ—ã‚’ *str* ã«ä¸ŽãˆãŸå ´åˆ,
    ! dc_date_types#UNIT_SYMBOL_ERR ãŒè¿”ã‚Šã¾ã™.
    !
    use dc_types, only: TOKEN
    use dc_date_types, only: UNIT_YEAR, UNIT_MONTH, UNIT_DAY, &
      & UNIT_HOUR, UNIT_MIN, UNIT_SEC, UNIT_NONDIM, &
      & UNIT_SYMBOL_YEAR, UNIT_SYMBOL_MONTH, UNIT_SYMBOL_DAY, &
      & UNIT_SYMBOL_HOUR, UNIT_SYMBOL_MIN, UNIT_SYMBOL_SEC, &
      & UNIT_SYMBOL_NONDIM, UNIT_SYMBOL_ERR
    use dc_string, only: StriEq
    implicit none
    character(*), intent(in):: str
    integer:: symbol
    integer:: unit_str_size, i
    character(TOKEN):: unit
  continue
    unit = adjustl(str)
    unit_str_size = size(UNIT_NONDIM)
    do i = 1, unit_str_size
      if (StriEq(trim(unit), trim(UNIT_NONDIM(i)))) then
        symbol = UNIT_SYMBOL_NONDIM
        return
      end if
    end do

    unit_str_size = size(UNIT_SEC)
    do i = 1, unit_str_size
      if (StriEq(trim(unit), trim(UNIT_SEC(i)))) then
        symbol = UNIT_SYMBOL_SEC
        return
      end if
    end do

    unit_str_size = size(UNIT_MIN)
    do i = 1, unit_str_size
      if (StriEq(trim(unit), trim(UNIT_MIN(i)))) then
        symbol = UNIT_SYMBOL_MIN
        return
      end if
    end do

    unit_str_size = size(UNIT_HOUR)
    do i = 1, unit_str_size
      if (StriEq(trim(unit), trim(UNIT_HOUR(i)))) then
        symbol = UNIT_SYMBOL_HOUR
        return
      end if
    end do

    unit_str_size = size(UNIT_DAY)
    do i = 1, unit_str_size
      if (StriEq(trim(unit), trim(UNIT_DAY(i)))) then
        symbol = UNIT_SYMBOL_DAY
        return
      end if
    end do

    unit_str_size = size(UNIT_MONTH)
    do i = 1, unit_str_size
      if (StriEq(trim(unit), trim(UNIT_MONTH(i)))) then
        symbol = UNIT_SYMBOL_MONTH
        return
      end if
    end do

    unit_str_size = size(UNIT_YEAR)
    do i = 1, unit_str_size
      if (StriEq(trim(unit), trim(UNIT_YEAR(i)))) then
        symbol = UNIT_SYMBOL_YEAR
        return
      end if
    end do

    symbol = UNIT_SYMBOL_ERR

  end function DCDateTimeParseUnits