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