gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
dcdatetimeparseunits.f90
Go to the documentation of this file.
1! -*- mode: f90; coding: utf-8 -*-
2!-----------------------------------------------------------------------
3! Copyright (c) 2000-2026 Gtool Development Group. All rights reserved.
4!-----------------------------------------------------------------------
5!>
6!> @author Yasuhiro MORIKAWA
7!> @copyright Copyright (C) GFD Dennou Club, 2000-2026. All rights reserved. <br/>
8!> License is BSD-2-Clause. see [COPYRIGHT](@ref COPYRIGHT) in detail
9!> @en
10!> @brief Parse strings that mean units
11!> @details
12!> This file contains the implementation procedure for parsing
13!> date/time unit strings.
14!> @enden
15!>
16!> @ja
17!> @brief 単位を表す文字列の解析
18!> @details
19!> このファイルには日時単位の文字列を解析する実装手続きが含まれています。
20!> @endja
21!>
22
23!> @en
24!> @brief Parse a unit string and return the corresponding symbol
25!> @details
26!> Parse the string given in `str` and return a symbol representing
27!> the date/time unit. The following strings are interpreted as
28!> date/time units. Case is not distinguished.
29!>
30!> | Unit | String constant |
31!> |-----------------------|--------------------------------|
32!> | Year | dc_date_types#UNIT_YEAR |
33!> | Month | dc_date_types#UNIT_MONTH |
34!> | Day | dc_date_types#UNIT_DAY |
35!> | Hour | dc_date_types#UNIT_HOUR |
36!> | Minute | dc_date_types#UNIT_MIN |
37!> | Second | dc_date_types#UNIT_SEC |
38!> | Non-dimensional time | dc_date_types#UNIT_NONDIM |
39!>
40!> The returned symbols (integer type) are as follows.
41!>
42!> | Unit | Symbol constant |
43!> |-----------------------|--------------------------------------|
44!> | Year | dc_date_types#UNIT_SYMBOL_YEAR |
45!> | Month | dc_date_types#UNIT_SYMBOL_MONTH |
46!> | Day | dc_date_types#UNIT_SYMBOL_DAY |
47!> | Hour | dc_date_types#UNIT_SYMBOL_HOUR |
48!> | Minute | dc_date_types#UNIT_SYMBOL_MIN |
49!> | Second | dc_date_types#UNIT_SYMBOL_SEC |
50!> | Non-dimensional time | dc_date_types#UNIT_SYMBOL_NONDIM |
51!>
52!> If a string not matching these is given to `str`,
53!> dc_date_types#UNIT_SYMBOL_ERR is returned.
54!>
55!> @param[in] str String to parse
56!> @return Symbol representing the date/time unit
57!> @enden
58!>
59!> @ja
60!> @brief 単位文字列を解析して対応するシンボルを返す
61!> @details
62!> 引数 `str` に与えられた文字列を解釈し, 日時の単位を示す
63!> シンボルを返します. それぞれ以下の文字列が日時の単位として解釈されます.
64!> 大文字と小文字は区別されません.
65!>
66!> | 単位 | 文字列定数 |
67!> |------------|--------------------------------|
68!> | 年 | dc_date_types#UNIT_YEAR |
69!> | 月 | dc_date_types#UNIT_MONTH |
70!> | 日 | dc_date_types#UNIT_DAY |
71!> | 時 | dc_date_types#UNIT_HOUR |
72!> | 分 | dc_date_types#UNIT_MIN |
73!> | 秒 | dc_date_types#UNIT_SEC |
74!> | 無次元時間 | dc_date_types#UNIT_NONDIM |
75!>
76!> 返るシンボル (整数型) は以下の通りです.
77!>
78!> | 単位 | シンボル定数 |
79!> |------------|--------------------------------------|
80!> | 年 | dc_date_types#UNIT_SYMBOL_YEAR |
81!> | 月 | dc_date_types#UNIT_SYMBOL_MONTH |
82!> | 日 | dc_date_types#UNIT_SYMBOL_DAY |
83!> | 時 | dc_date_types#UNIT_SYMBOL_HOUR |
84!> | 分 | dc_date_types#UNIT_SYMBOL_MIN |
85!> | 秒 | dc_date_types#UNIT_SYMBOL_SEC |
86!> | 無次元時間 | dc_date_types#UNIT_SYMBOL_NONDIM |
87!>
88!> これらに該当しない文字列を `str` に与えた場合,
89!> dc_date_types#UNIT_SYMBOL_ERR が返ります.
90!>
91!> @param[in] str 解析する文字列
92!> @return 日時の単位を示すシンボル
93!> @endja
94function dcdatetimeparseunits(str) result(symbol)
95
96 use dc_types, only: token
102 use dc_string, only: strieq
103 implicit none
104 character(*), intent(in):: str
105 integer:: symbol
106 integer:: unit_str_size, i
107 character(TOKEN):: unit
108continue
109 unit = adjustl(str)
110 unit_str_size = size(unit_nondim)
111 do i = 1, unit_str_size
112 if (strieq(trim(unit), trim(unit_nondim(i)))) then
113 symbol = unit_symbol_nondim
114 return
115 end if
116 end do
117
118 unit_str_size = size(unit_sec)
119 do i = 1, unit_str_size
120 if (strieq(trim(unit), trim(unit_sec(i)))) then
121 symbol = unit_symbol_sec
122 return
123 end if
124 end do
125
126 unit_str_size = size(unit_min)
127 do i = 1, unit_str_size
128 if (strieq(trim(unit), trim(unit_min(i)))) then
129 symbol = unit_symbol_min
130 return
131 end if
132 end do
133
134 unit_str_size = size(unit_hour)
135 do i = 1, unit_str_size
136 if (strieq(trim(unit), trim(unit_hour(i)))) then
137 symbol = unit_symbol_hour
138 return
139 end if
140 end do
141
142 unit_str_size = size(unit_day)
143 do i = 1, unit_str_size
144 if (strieq(trim(unit), trim(unit_day(i)))) then
145 symbol = unit_symbol_day
146 return
147 end if
148 end do
149
150 unit_str_size = size(unit_month)
151 do i = 1, unit_str_size
152 if (strieq(trim(unit), trim(unit_month(i)))) then
153 symbol = unit_symbol_month
154 return
155 end if
156 end do
157
158 unit_str_size = size(unit_year)
159 do i = 1, unit_str_size
160 if (strieq(trim(unit), trim(unit_year(i)))) then
161 symbol = unit_symbol_year
162 return
163 end if
164 end do
165
166 symbol = unit_symbol_err
167
168end function dcdatetimeparseunits
integer function dcdatetimeparseunits(str)
Parse strings that mean units.
Derived types and parameters for date and time.
character(*), dimension(6), parameter, public unit_month
Strings recognized as month unit
integer, parameter, public unit_symbol_err
Symbol for invalid unit
integer, parameter, public unit_symbol_hour
Symbol for hour unit
integer, parameter, public unit_symbol_min
Symbol for minute unit
integer, parameter, public unit_symbol_month
Symbol for month unit
character(*), dimension(1), parameter, public unit_nondim
Strings recognized as nondimensional unit
integer, parameter, public unit_symbol_sec
Symbol for second unit
integer, parameter, public unit_symbol_nondim
Symbol for nondimensional unit
character(*), dimension(4), parameter, public unit_day
Strings recognized as day unit
character(*), dimension(8), parameter, public unit_sec
Strings recognized as second unit
character(*), dimension(8), parameter, public unit_hour
Strings recognized as hour unit
integer, parameter, public unit_symbol_day
Symbol for day unit
character(*), dimension(4), parameter, public unit_year
Strings recognized as year unit
integer, parameter, public unit_symbol_year
Symbol for year unit
character(*), dimension(4), parameter, public unit_min
Strings recognized as minute unit
Handling character types.
Definition dc_string.f90:83
Provides kind type parameter values.
Definition dc_types.f90:55
integer, parameter, public token
Character length for word, token
Definition dc_types.f90:128