gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
dccaldateinquire.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, 2009-2026. All rights reserved. <br/>
8!> License is BSD-2-Clause. see [COPYRIGHT](@ref COPYRIGHT) in detail
9!> @en
10!> @brief Inquire information of date
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 Inquire date information as individual variables
24!> @details
25!> Inquire information of date.
26!>
27!> If a string like as "YYYY-MM-DDThh:mm:ss.sTZD"
28!> (YYYY is year, MM is month, DD is day, hh is hour, mm is minute,
29!> ss.s is second, TZD is time zone) is needed,
30!> use a following homonymous subroutine.
31!>
32!> If an optional argument `date` is omitted,
33!> information of date that is stored in the "dc_calendar"
34!> is returned,
35!> If `date` is not omitted, information of the variable is returned.
36!>
37!> If an optional argument `cal` is omitted,
38!> information of calendar that is stored in the "dc_calendar"
39!> is used for conversion of elapsed seconds `elapse_sec` into
40!> year-month-day etc.
41!> If `cal` is not omitted, information of the variable is used.
42!>
43!> @param[out] year Year
44!> @param[out] month Month
45!> @param[out] day Day
46!> @param[out] hour Hour
47!> @param[out] min Minute
48!> @param[out] sec Second
49!> @param[out] zone Time-zone (difference from UTC)
50!> @param[in] elapse_sec Elapsed seconds from `date`
51!> @param[in] date An object that stores information of date and time
52!> @param[in] cal An object that stores information of calendar
53!> @param[out] err Exception handling flag.
54!> By default, when error occur in this procedure, the program aborts.
55!> If this `err` argument is given, .true. is substituted to `err` and
56!> the program does not abort.
57!> @enden
58!>
59!> @ja
60!> @brief 日時情報を個別変数で問い合わせ
61!> @details
62!> 日時情報の問い合わせを行います.
63!>
64!> 問い合わせの結果を
65!> YYYY-MM-DDThh:mm:ss.sTZD のような文字列
66!> (YYYY は年, MM は月, DD は日, hh は時, mm は分, ss.s は秒,
67!> TZD はタイムゾーン) で受け取りたい場合には,
68!> 下記の同名のサブルーチンを使用して下さい.
69!>
70!> 省略可能引数 `date` が省略された場合には, dc_calendar 内部で
71!> 保持される日時に関する情報が得られます.
72!> `date` が省略されない場合にはその変数に設定された日時の情報が得られます.
73!>
74!> 省略可能引数 `cal` が省略された場合には, 経過秒数 `elapse_sec`
75!> の年月日時分への変換に dc_calendar 内部で保持される暦が用いられます.
76!> `cal` が省略されない場合にはその変数に設定された暦が用いられます.
77!>
78!> @param[out] year 年
79!> @param[out] month 月
80!> @param[out] day 日
81!> @param[out] hour 時
82!> @param[out] min 分
83!> @param[out] sec 秒
84!> @param[out] zone UTC からの時差
85!> @param[in] elapse_sec `date` からの経過秒数
86!> @param[in] date 日時情報を収めたオブジェクト
87!> @param[in] cal 暦情報を収めたオブジェクト
88!> @param[out] err 例外処理用フラグ.
89!> デフォルトでは, この手続き内でエラーが生じた場合,
90!> プログラムは強制終了します.
91!> 引数 `err` が与えられる場合, プログラムは強制終了せず,
92!> 代わりに `err` に .true. が代入されます.
93!> @endja
94subroutine dccaldateinquire1( year, month, day, hour, min, sec, zone, &
95 & elapse_sec, date, cal, err )
96
101 use dc_message, only: messagenotify
102 use dc_string, only: lchar
103 use dc_trace, only: beginsub, endsub
106 use dc_types, only: string, dp, token
107 implicit none
108 integer, intent(out), optional:: year
109 integer, intent(out), optional:: month
110 integer, intent(out), optional:: day
111 integer, intent(out), optional:: hour
112 integer, intent(out), optional:: min
113 real(DP), intent(out), optional:: sec
114 character(*), intent(out), optional:: zone
115 real(DP), intent(in), optional:: elapse_sec
116 type(dc_cal_date), intent(in), optional, target:: date
117 type(dc_cal), intent(in), optional, target:: cal
118 logical, intent(out), optional:: err
119
120 ! 作業変数
121 ! Work variables
122 !
123 integer:: wyear, wmonth, wday, whour, wmin
124 real(DP):: wsec
125 character(TOKEN):: wzone
126 type(dc_cal_date), pointer:: datep =>null()
127 type(dc_cal), pointer:: calp =>null()
128 character(STRING):: e_date_str, e_cal_str
129 integer:: stat
130 character(STRING):: cause_c
131 character(*), parameter:: subname = 'DCCalInquire1'
132continue
133 call beginsub( subname )
134 stat = dc_noerr
135 cause_c = ''
136
137 ! オブジェクトのポインタ割付
138 ! Associate pointer of an object
139 !
140 if ( present( date ) ) then
141 datep => date
142 else
143 datep => default_date
144 end if
145
146 if ( present( cal ) ) then
147 calp => cal
148 else
149 calp => default_cal
150 if ( .not. calp % initialized ) call default_cal_set
151 end if
152
153 ! 初期設定のチェック
154 ! Check initialization
155 !
156 if ( .not. datep % initialized ) then
157 stat = dc_enotinit
158 cause_c = 'DC_CAL_DATE'
159 goto 999
160 end if
161
162 if ( .not. calp % initialized ) then
163 stat = dc_enotinit
164 cause_c = 'DC_CAL'
165 goto 999
166 end if
167
168 ! 各要素への値の参照
169 ! Refer elements
170 !
171 wyear = datep % year
172 wmonth = datep % month
173 wday = datep % day
174 whour = datep % hour
175 wmin = datep % min
176 wsec = datep % sec
177 wzone = datep % zone
178
179 ! 経過時間(秒)の追加
180 ! Add elapsed time (seconds)
181 !
182 if ( present( elapse_sec ) ) then
183!!$ if ( elapse_sec < 0.0_DP ) then
184!!$ stat = DC_ENEGATIVE
185!!$ cause_c = 'elapse_sec'
186!!$ goto 999
187!!$ end if
188
189 wsec = wsec + elapse_sec
190 end if
191
192 ! 日時の正規化
193 ! Normalize date and time
194 !
195 stat = dccaldate_normalize( wyear, wmonth, wday, whour, wmin, wsec, & ! (inout)
196 & calp ) ! (in)
197 if ( stat == dc_einconsistcaldate ) then
198 e_cal_str = dccaltochar( calp )
199 e_date_str = dccaldatetochar( wyear, wmonth, wday, whour, wmin, wsec, wzone )
200 call messagenotify('W', subname, 'cal=<%c> and date=<%c> are inconsistency', &
201 & c1 = trim(e_cal_str), c2 = trim(e_date_str) )
202 goto 999
203 end if
204
205 ! 引数への代入
206 ! Substitute arguments
207 !
208 if ( present(year ) ) year = wyear
209 if ( present(month) ) month = wmonth
210 if ( present(day ) ) day = wday
211 if ( present(hour ) ) hour = whour
212 if ( present(min ) ) min = wmin
213 if ( present(sec ) ) sec = wsec
214 if ( present(zone ) ) zone = wzone
215
216 ! 終了処理, 例外処理
217 ! Termination and Exception handling
218 !
219999 continue
220 nullify( calp, datep )
221 call storeerror( stat, subname, err, cause_c )
222 call endsub( subname )
223end subroutine dccaldateinquire1
224
225!> @en
226!> @brief Inquire date information as a string
227!> @details
228!> Inquire information of date.
229!> A result is returned as a string like as
230!> YYYY-MM-DDThh:mm:ss.sTZD
231!> (YYYY is year, MM is month, DD is day, hh is hour, mm is minute,
232!> ss.s is second, TZD is time zone).
233!> Format of date is conformed to gtool4 netCDF Convention "5.5 Expression of date and time"
234!>
235!> If individual variables (year, month, day, hour, minute, second, zone)
236!> are needed, use a foregoing homonymous subroutine.
237!>
238!> If an optional argument `date` is omitted,
239!> information of date that is stored in the "dc_calendar"
240!> is returned,
241!> If `date` is not omitted, information of the variable is returned.
242!>
243!> If an optional argument `cal` is omitted,
244!> information of calendar that is stored in the "dc_calendar"
245!> is used for conversion of elapsed seconds `elapse_sec` into
246!> year-month-day etc.
247!> If `cal` is not omitted, information of the variable is used.
248!>
249!> @param[out] date_str Strings that express date and time.
250!> See gtool4 netCDF Convention 5.5 Expression of date and time for details.
251!> @param[in] elapse_sec Elapsed seconds from `date`
252!> @param[in] date An object that stores information of date and time
253!> @param[in] cal An object that stores information of calendar
254!> @param[out] err Exception handling flag.
255!> By default, when error occur in this procedure, the program aborts.
256!> If this `err` argument is given, .true. is substituted to `err` and
257!> the program does not abort.
258!> @enden
259!>
260!> @ja
261!> @brief 日時情報を文字列で問い合わせ
262!> @details
263!> 日時情報の問い合わせを行います.
264!> 問い合わせ結果は YYYY-MM-DDThh:mm:ss.sTZD のような文字列
265!> (YYYY は年, MM は月, DD は日, hh は時, mm は分, ss.s は秒,
266!> TZD はタイムゾーン) で返ります.
267!> 日時の文字列形式は
268!> gtool4 netCDF 規約「5.5 日時形式」に準拠しています.
269!>
270!> 問い合わせの結果を年月日時分秒で各個変数で受け取りたい場合は
271!> 上記の同名のサブルーチンを使用して下さい.
272!>
273!> 省略可能引数 `date` が省略された場合には, dc_calendar 内部で
274!> 保持される日時に関する情報が得られます.
275!> `date` が省略されない場合にはその変数に設定された日時の情報が得られます.
276!>
277!> 省略可能引数 `cal` が省略された場合には, 経過秒数 `elapse_sec`
278!> の年月日時分への変換に dc_calendar 内部で保持される暦が用いられます.
279!> `cal` が省略されない場合にはその変数に設定された暦が用いられます.
280!>
281!> @param[out] date_str 日時情報を表す文字列.
282!> 表示形式については gtool4 netCDF 規約 5.5 日時形式を参照のこと.
283!> @param[in] elapse_sec `date` からの経過秒数
284!> @param[in] date 日時情報を収めたオブジェクト
285!> @param[in] cal 暦情報を収めたオブジェクト
286!> @param[out] err 例外処理用フラグ.
287!> デフォルトでは, この手続き内でエラーが生じた場合,
288!> プログラムは強制終了します.
289!> 引数 `err` が与えられる場合, プログラムは強制終了せず,
290!> 代わりに `err` に .true. が代入されます.
291!> @endja
292subroutine dccaldateinquire2( date_str, elapse_sec, date, cal, err )
293
299 use dc_message, only: messagenotify
300 use dc_string, only: lchar
301 use dc_trace, only: beginsub, endsub
304 use dc_types, only: string, dp, token
305 implicit none
306 character(*), intent(out):: date_str
307 real(DP), intent(in), optional:: elapse_sec
308 type(dc_cal_date), intent(in), optional, target:: date
309 type(dc_cal), intent(in), optional, target:: cal
310 logical, intent(out), optional:: err
311
312 ! 作業変数
313 ! Work variables
314 !
315 integer:: year, month, day, hour, min
316 real(DP):: sec
317 character(TOKEN):: zone
318 type(dc_cal_date), pointer:: datep =>null()
319 type(dc_cal), pointer:: calp =>null()
320 character(STRING):: e_date_str, e_cal_str
321 integer:: stat
322 character(STRING):: cause_c
323 character(*), parameter:: subname = 'DCCalInquire2'
324continue
325 call beginsub( subname )
326 stat = dc_noerr
327 cause_c = ''
328
329 ! オブジェクトのポインタ割付
330 ! Associate pointer of an object
331 !
332 if ( present( date ) ) then
333 datep => date
334 else
335 datep => default_date
336 end if
337
338 if ( present( cal ) ) then
339 calp => cal
340 else
341 calp => default_cal
342 if ( .not. calp % initialized ) call default_cal_set
343 end if
344
345 ! 初期設定のチェック
346 ! Check initialization
347 !
348 if ( .not. datep % initialized ) then
349 stat = dc_enotinit
350 cause_c = 'DC_CAL_DATE'
351 goto 999
352 end if
353
354 if ( .not. calp % initialized ) then
355 stat = dc_enotinit
356 cause_c = 'DC_CAL'
357 goto 999
358 end if
359
360 ! 各要素の取得
361 ! Get elements
362 !
363 year = datep % year
364 month = datep % month
365 day = datep % day
366 hour = datep % hour
367 min = datep % min
368 sec = datep % sec
369 zone = datep % zone
370
371
372 ! 経過時間(秒)の追加
373 ! Add elapsed time (seconds)
374 !
375 if ( present( elapse_sec ) ) then
376!!$ if ( elapse_sec < 0.0_DP ) then
377!!$ stat = DC_ENEGATIVE
378!!$ cause_c = 'elapse_sec'
379!!$ goto 999
380!!$ end if
381
382 sec = sec + elapse_sec
383 end if
384
385 ! 日時の正規化
386 ! Normalize date and time
387 !
388 stat = dccaldate_normalize( year, month, day, hour, min, sec, & ! (inout)
389 & calp ) ! (in)
390 if ( stat == dc_einconsistcaldate ) then
391 e_cal_str = dccaltochar( calp )
392 e_date_str = dccaldatetochar( year, month, day, hour, min, sec, zone )
393 call messagenotify('W', subname, 'cal=<%c> and date=<%c> are inconsistency', &
394 & c1 = trim(e_cal_str), c2 = trim(e_date_str) )
395 goto 999
396 end if
397
398 ! 日時表記(gtool4 netCDF 規約 5.5 日時形式)への変換
399 ! Convert expression of date (gtool4 netCDF Convention 5.5 Expression of date and time)
400 !
401 date_str = dccaldatetochar( year, month, day, hour, min, sec, zone )
402
403 ! 終了処理, 例外処理
404 ! Termination and Exception handling
405 !
406999 continue
407 nullify( calp, datep )
408 call storeerror( stat, subname, err, cause_c )
409 call endsub( subname )
410end subroutine dccaldateinquire2
subroutine dccaldateinquire1(year, month, day, hour, min, sec, zone, elapse_sec, date, cal, err)
Inquire information of date.
subroutine dccaldateinquire2(date_str, elapse_sec, date, cal, err)
Interface declarations for dc_calendar procedures.
Internal module for dc_calendar.
type(dc_cal), target, save, public default_cal
Default calendar object
type(dc_cal_date), target, save, public default_date
Default date object
integer function, public dccaldate_normalize(year, month, day, hour, min, sec, cal)
subroutine, public default_cal_set
Derived types and parameters of calendar and date.
Error handling module.
Definition dc_error.f90:454
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition dc_error.f90:891
integer, parameter, public dc_enotinit
-400 or less: DC utilities errors
Definition dc_error.f90:534
integer, parameter, public dc_noerr
Error storage variables
Definition dc_error.f90:468
integer, parameter, public dc_einconsistcaldate
Definition dc_error.f90:553
Message output module.
Handling character types.
Definition dc_string.f90:83
Debug tracing module.
Definition dc_trace.f90:150
subroutine, public beginsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca, version)
Definition dc_trace.f90:476
subroutine, public endsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca)
Definition dc_trace.f90:599
Provides kind type parameter values.
Definition dc_types.f90:55
integer, parameter, public token
Character length for word, token
Definition dc_types.f90:128
integer, parameter, public string
Character length for string
Definition dc_types.f90:137
integer, parameter, public dp
Double Precision Real number
Definition dc_types.f90:92