gtool5 Fortran 90/95 ライブラリ 1.0.0-rc5
English
Loading...
Searching...
No Matches
dccalconvertbyunit.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 Youhei SASAKI, Yasuhiro MORIKAWA
7!> @copyright Copyright (C) GFD Dennou Club, 2009-2026. All rights reserved. <br/>
8!> License is BSD-2-Clause. see [COPYRIGHT](@ref COPYRIGHT) in detail
9!> @en
10!> @brief Unit conversion functions for calendar
11!> @details
12!> Procedures described in this file are provided from "dc_calendar" module.
13!> @enden
14!>
15!> @ja
16!> @brief 暦の単位変換関数
17!> @details
18!> このファイルに記載される手続き群は dc_calendar モジュールから提供されます.
19!> @endja
20!>
21
22!> @en
23!> @brief Convert time value between different units (string version)
24!> @details
25!> Convert of unit.
26!>
27!> Valid strings as units of time are follows.
28!>
29!> | Parameter | Description |
30!> |--------------------------------|-------------------|
31!> | dc_calendar_types#UNIT_SEC | Units of second |
32!> | dc_calendar_types#UNIT_MIN | Units of minute |
33!> | dc_calendar_types#UNIT_HOUR | Units of hour |
34!> | dc_calendar_types#UNIT_DAY | Units of day |
35!>
36!> If an optional argument `cal` is omitted,
37!> unit is converted with information of a calendar
38!> that is stored in the "dc_calendar".
39!> If `cal` is not omitted, unit is converted with information of the variable.
40!>
41!> @param[in] in_time Numerical value of time before conversion
42!> @param[in] in_unit Units of time before conversion (string)
43!> @param[in] out_unit Units of time after conversion (string)
44!> @param[in] cal An object that stores information of calendar
45!> @return Numerical value of time after conversion
46!> @enden
47!>
48!> @ja
49!> @brief 時間値を異なる単位間で変換 (文字列版)
50!> @details
51!> 単位の変換を行います.
52!>
53!> 時間の単位として有効な文字列については以下を参照下さい.
54!>
55!> | パラメータ | 説明 |
56!> |--------------------------------|-------------------|
57!> | dc_calendar_types#UNIT_SEC | 秒の単位 |
58!> | dc_calendar_types#UNIT_MIN | 分の単位 |
59!> | dc_calendar_types#UNIT_HOUR | 時間の単位 |
60!> | dc_calendar_types#UNIT_DAY | 日の単位 |
61!>
62!> 省略可能引数 `cal` が省略された場合には, dc_calendar 内部で
63!> 保持される暦に関する情報を用いた単位の変換が行われます.
64!> `cal` が省略されない場合にはその変数に設定された暦の情報を
65!> 用いて単位の変換が行われます.
66!>
67!> @param[in] in_time 変換前の時間の数値
68!> @param[in] in_unit 変換前の時間の単位 (文字列)
69!> @param[in] out_unit 変換後の時間の単位 (文字列)
70!> @param[in] cal 暦情報を収めたオブジェクト
71!> @return 変換後の時間の数値
72!> @endja
73function dccalconvertbyunit1( in_time, in_unit, out_unit, cal ) result( out_time )
74
77 use dc_calendar_types, only: dc_cal
79 use dc_message, only: messagenotify
80 use dc_types, only: dp
81 implicit none
82 real(dp):: out_time
83 real(dp), intent(in):: in_time
84 character(*), intent(in):: in_unit
85 character(*), intent(in):: out_unit
86 type(dc_cal), intent(in), optional, target:: cal
87
88 ! 作業変数
89 ! Work variables
90 !
91 type(dc_cal), pointer:: calp =>null()
92 integer:: in_unit_sym, out_unit_sym
93 character(*), parameter:: subname = 'DCCalConvertByUnit1'
94continue
95
96 out_time = -1.0
97
98 ! オブジェクトのポインタ割付
99 ! Associate pointer of an object
100 !
101 if ( present( cal ) ) then
102 calp => cal
103 else
104 calp => default_cal
105 if ( .not. calp % initialized ) call default_cal_set
106 end if
107
108 ! 初期設定のチェック
109 ! Check initialization
110 !
111 if ( .not. calp % initialized ) then
112 call messagenotify('W', subname, '"cal" is not initialized. <-1> is returned.' )
113 goto 999
114 end if
115
116 ! 単位の解釈
117 ! Parse units
118 !
119 in_unit_sym = dccaldate_str2usym( in_unit )
120 out_unit_sym = dccaldate_str2usym( out_unit )
121
122 ! 数値の変換
123 ! Convert a value
124 !
125 out_time = dccalconvertbyunit( in_time, in_unit_sym, out_unit_sym, cal )
126
127 ! 終了処理, 例外処理
128 ! Termination and Exception handling
129 !
130999 continue
131 nullify( calp )
132end function dccalconvertbyunit1
133
134!---------------------------------------------------------------------
135
136!> @en
137!> @brief Convert time value between different units (symbol version)
138!> @details
139!> Convert of unit.
140!>
141!> Valid integer variables as units of time are follows.
142!> Do not specify integer directly, but specify following variables.
143!>
144!> | Parameter | Description |
145!> |-------------------------------------|-------------------|
146!> | dc_calendar_types#UNIT_SYMBOL_SEC | Units of second |
147!> | dc_calendar_types#UNIT_SYMBOL_MIN | Units of minute |
148!> | dc_calendar_types#UNIT_SYMBOL_HOUR | Units of hour |
149!> | dc_calendar_types#UNIT_SYMBOL_DAY | Units of day |
150!>
151!> If an optional argument `cal` is omitted,
152!> unit is converted with information of a calendar
153!> that is stored in the "dc_calendar".
154!> If `cal` is not omitted, unit is converted with information of the variable.
155!>
156!> @param[in] in_time Numerical value of time before conversion
157!> @param[in] in_unit Units of time before conversion (integer symbol)
158!> @param[in] out_unit Units of time after conversion (integer symbol)
159!> @param[in] cal An object that stores information of calendar
160!> @return Numerical value of time after conversion
161!> @enden
162!>
163!> @ja
164!> @brief 時間値を異なる単位間で変換 (シンボル版)
165!> @details
166!> 単位の変換を行います.
167!>
168!> 時間の単位として有効な整数型変数については以下を参照下さい.
169!> 単位として整数値を直接与えることはせず, 以下の変数を与えてください.
170!>
171!> | パラメータ | 説明 |
172!> |-------------------------------------|-------------------|
173!> | dc_calendar_types#UNIT_SYMBOL_SEC | 秒の単位 |
174!> | dc_calendar_types#UNIT_SYMBOL_MIN | 分の単位 |
175!> | dc_calendar_types#UNIT_SYMBOL_HOUR | 時間の単位 |
176!> | dc_calendar_types#UNIT_SYMBOL_DAY | 日の単位 |
177!>
178!> 省略可能引数 `cal` が省略された場合には, dc_calendar 内部で
179!> 保持される暦に関する情報を用いた単位の変換が行われます.
180!> `cal` が省略されない場合にはその変数に設定された暦の情報を
181!> 用いて単位の変換が行われます.
182!>
183!> @param[in] in_time 変換前の時間の数値
184!> @param[in] in_unit 変換前の時間の単位 (整数シンボル)
185!> @param[in] out_unit 変換後の時間の単位 (整数シンボル)
186!> @param[in] cal 暦情報を収めたオブジェクト
187!> @return 変換後の時間の数値
188!> @endja
189function dccalconvertbyunit2( in_time, in_unit, out_unit, cal ) result( out_time )
190
192 use dc_calendar_types, only: dc_cal, &
194 use dc_message, only: messagenotify
195 use dc_types, only: dp
196 implicit none
197 real(dp):: out_time
198 real(dp), intent(in):: in_time
199 integer, intent(in):: in_unit
200 integer, intent(in):: out_unit
201 type(dc_cal), intent(in), optional, target:: cal
202
203 ! 作業変数
204 ! Work variables
205 !
206 type(dc_cal), pointer:: calp =>null()
207 real(dp):: in_timew
208 character(*), parameter:: subname = 'DCCalConvertByUnit2'
209continue
210
211 out_time = -1.0
212
213 ! オブジェクトのポインタ割付
214 ! Associate pointer of an object
215 !
216 if ( present( cal ) ) then
217 calp => cal
218 else
219 calp => default_cal
220 if ( .not. calp % initialized ) call default_cal_set
221 end if
222
223 ! 初期設定のチェック
224 ! Check initialization
225 !
226 if ( .not. calp % initialized ) then
227 call messagenotify('W', subname, '"cal" is not initialized. <-1> is returned.' )
228 goto 999
229 end if
230
231 ! 数値の変換
232 ! Convert a value
233 !
234 select case(in_unit)
235 case(unit_symbol_day)
236 in_timew = in_time * calp % hour_in_day &
237 & * calp % min_in_hour &
238 & * calp % sec_in_min
239 case(unit_symbol_hour)
240 in_timew = in_time * calp % min_in_hour &
241 & * calp % sec_in_min
242 case(unit_symbol_min)
243 in_timew = in_time * calp % sec_in_min
244 case(unit_symbol_sec)
245 in_timew = in_time
246 case default
247 call messagenotify('W', subname, 'in_unit=<%d> is invalid. (ONLY day,hour,min,sec are valid).' // &
248 & ' <-1> is returned.', &
249 & i = (/ in_unit /) )
250 goto 999
251 end select
252
253 select case(out_unit)
254 case(unit_symbol_day)
255 out_time = in_timew / calp % hour_in_day &
256 & / calp % min_in_hour &
257 & / calp % sec_in_min
258 case(unit_symbol_hour)
259 out_time = in_timew / calp % min_in_hour &
260 & / calp % sec_in_min
261 case(unit_symbol_min)
262 out_time = in_timew / calp % sec_in_min
263 case(unit_symbol_sec)
264 out_time = in_timew
265 case default
266 call messagenotify('W', subname, 'out_unit=<%d> is invalid. (ONLY day,hour,min,sec are valid).' // &
267 & ' <-1> is returned.', &
268 & i = (/ out_unit /) )
269 goto 999
270 end select
271
272 ! 終了処理, 例外処理
273 ! Termination and Exception handling
274 !
275999 continue
276 nullify( calp )
277end function dccalconvertbyunit2
real(dp) function dccalconvertbyunit1(in_time, in_unit, out_unit, cal)
暦の単位変換関数
real(dp) function dccalconvertbyunit2(in_time, in_unit, out_unit, cal)
dc_calendar 手続のインターフェース宣言
dc_calendar用の内部モジュール
type(dc_cal), target, save, public default_cal
デフォルトの暦. DCCal で始まる手続のうち, DC_CAL 型の省略可能引数が与えられない 場合にはこの暦が設定もしくは利用される.
subroutine, public default_cal_set
integer function, public dccaldate_str2usym(str)
暦と日時に関する構造データ型と定数
integer, parameter, public unit_symbol_sec
integer, parameter, public unit_symbol_hour
integer, parameter, public unit_symbol_day
integer, parameter, public unit_symbol_min
メッセージの出力
種別型パラメタを提供します。
Definition dc_types.f90:55
integer, parameter, public dp
倍精度実数型変数
Definition dc_types.f90:92