gtool5 Fortran 90/95 ライブラリ 1.0.0-rc5
English
Loading...
Searching...
No Matches
dccaldatecreate.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 Date setting procedures
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 Set date with individual variables
24!> @details
25!> Set 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 used,
30!> use a following homonymous subroutine.
31!>
32!> If an optional argument `date` is omitted,
33!> the date setting is stored to a "dc_calendar_types#DC_CAL_DATE"
34!> variable that is saved in the "dc_calendar".
35!> When `date` is omitted in subsequent procedures, the internal date
36!> is used.
37!> If `date` is not omitted, the settings is stored to the `date`.
38!> In order to use the date setting, use the "dc_calendar_types#DC_CAL_DATE"
39!> variable to subsequent procedures.
40!>
41!> @param[in] year Year
42!> @param[in] month Month
43!> @param[in] day Day
44!> @param[in] hour Hour
45!> @param[in] min Minute
46!> @param[in] sec Second
47!> @param[out] date An object that stores information of date and time.
48!> If this is omitted, these information is set as default date and time.
49!> @param[in] zone Time-zone (difference from UTC)
50!> @param[out] err Exception handling flag.
51!> By default, when error occur in this procedure, the program aborts.
52!> If this `err` argument is given, .true. is substituted to `err` and
53!> the program does not abort.
54!> @enden
55!>
56!> @ja
57!> @brief 個別変数で日時を設定
58!> @details
59!> 日時の設定を行います.
60!>
61!> YYYY-MM-DDThh:mm:ss.sTZD のような文字列
62!> (YYYY は年, MM は月, DD は日, hh は時, mm は分, ss.s は秒,
63!> TZD はタイムゾーン) で指定する場合には
64!> 下記の同名のサブルーチンを使用して下さい.
65!>
66!> 省略可能引数 `date` が省略された場合には, dc_calendar 内部で
67!> 保持される "dc_calendar_types#DC_CAL_DATE" 型の変数に日時が
68!> 設定されます. その後の手続きで `date` を省略した場合には
69!> この日時が使用されます.
70!> `date` が省略されない場合にはその変数に日時が設定されます.
71!> その日時を使用する場合, 手続きにその "dc_calendar_types#DC_CAL_DATE" 型の変数
72!> を与えてください.
73!>
74!> @param[in] year 年
75!> @param[in] month 月
76!> @param[in] day 日
77!> @param[in] hour 時
78!> @param[in] min 分
79!> @param[in] sec 秒
80!> @param[out] date 日時情報を収めたオブジェクト.
81!> 省略した場合には, デフォルトの日時として指定される.
82!> @param[in] zone UTC からの時差
83!> @param[out] err 例外処理用フラグ.
84!> デフォルトでは, この手続き内でエラーが生じた場合,
85!> プログラムは強制終了します.
86!> 引数 `err` が与えられる場合, プログラムは強制終了せず,
87!> 代わりに `err` に .true. が代入されます.
88!> @endja
89subroutine dccaldatecreate1( year, month, day, hour, min, sec, date, zone, err )
90
93 use dc_regex, only: match
94 use dc_message, only: messagenotify
95 use dc_string, only: lchar
96 use dc_trace, only: beginsub, endsub
98 use dc_types, only: string, dp
99 implicit none
100 integer, intent(in):: year
101 integer, intent(in):: month
102 integer, intent(in):: day
103 integer, intent(in):: hour
104 integer, intent(in):: min
105 real(DP), intent(in):: sec
106 type(dc_cal_date), intent(out), optional, target:: date
107 character(*), intent(in), optional:: zone
108 logical, intent(out), optional:: err
109
110 ! 作業変数
111 ! Work variables
112 !
113 type(dc_cal_date), pointer:: datep =>null()
114 integer:: start, length
115 integer:: stat
116 character(STRING):: cause_c
117 character(*), parameter:: version = &
118 & '$Name: $' // &
119 & '$Id: dccaldatecreate.f90,v 1.3 2010-09-24 07:07:31 morikawa Exp $'
120 character(*), parameter:: subname = 'DCCalDateCreate1'
121continue
122 call beginsub( subname, version )
123 stat = dc_noerr
124 cause_c = ''
125
126 ! オブジェクトのポインタ割付
127 ! Associate pointer of an object
128 !
129 if ( present( date ) ) then
130 datep => date
131 else
132 datep => default_date
133 end if
134
135!!$ ! 初期設定のチェック
136!!$ ! Check initialization
137!!$ !
138!!$ if ( datep % initialized ) then
139!!$ stat = DC_EALREADYINIT
140!!$ cause_c = 'DC_CAL_DATE'
141!!$ goto 999
142!!$ end if
143
144 ! 日時の正当性のチェック
145 ! Validate date and time
146 !
147!!$ if ( year < 1 ) then
148!!$ stat = DC_EBADDATE
149!!$ call MessageNotify('W', subname, 'year=<%d> must be natural number', &
150!!$ & i = (/ year /) )
151!!$ goto 999
152!!$ end if
153
154 if ( month < 1 ) then
155 stat = dc_ebaddate
156 call messagenotify('W', subname, 'month=<%d> must be natural number', &
157 & i = (/ month /) )
158 goto 999
159 end if
160
161 if ( day < 1 ) then
162 stat = dc_ebaddate
163 call messagenotify('W', subname, 'day=<%d> must be natural number', &
164 & i = (/ day /) )
165 goto 999
166 end if
167
168 if ( hour < 0 ) then
169 stat = dc_ebaddate
170 call messagenotify('W', subname, 'hour=<%d> must not be negative', &
171 & i = (/ hour /) )
172 goto 999
173 end if
174
175 if ( min < 0 ) then
176 stat = dc_ebaddate
177 call messagenotify('W', subname, 'min=<%d> must not be negative', &
178 & i = (/ min /) )
179 goto 999
180 end if
181
182 if ( sec < 0.0_dp ) then
183 stat = dc_ebaddate
184 call messagenotify('W', subname, 'sec=<%f> must not be negative', &
185 & d = (/ sec /) )
186 goto 999
187 end if
188
189 call match( '^[#+-]#d+:#d+$', zone, & ! (in)
190 & start, length ) ! (out)
191 if ( length > 0 ) then
192 datep % zone = zone
193 else
194 datep % zone = ''
195 end if
196
197 ! 各要素への値の設定
198 ! Configure elements
199 !
200 datep % year = year
201 datep % month = month
202 datep % day = day
203 datep % hour = hour
204 datep % min = min
205 datep % sec = sec
206
207 ! 終了処理, 例外処理
208 ! Termination and Exception handling
209 !
210 datep % initialized = .true.
211999 continue
212 nullify( datep )
213 call storeerror( stat, subname, err, cause_c )
214 call endsub( subname )
215end subroutine dccaldatecreate1
216
217!> @en
218!> @brief Set date with date string
219!> @details
220!> Set date.
221!>
222!> Specify a string like as "YYYY-MM-DDThh:mm:ss.sTZD"
223!> (YYYY is year, MM is month, DD is day, hh is hour, mm is minute,
224!> ss.s is second, TZD is time zone) to `date_str`.
225!> If individual variables (year, month, day, hour, minute, second, zone)
226!> are used, use a foregoing homonymous subroutine.
227!> Format of date is conformed to gtool4 netCDF Convention "5.5 Expression of date and time"
228!>
229!> If a string like as "s since 2009-06-17T11:23:45+09:00" is specified,
230!> A part "s since " is truncated automatically, and
231!> a part "2009-06-17T11:23:45+09:00" is set.
232!>
233!> If an optional argument `date` is omitted,
234!> the date setting is stored to a "dc_calendar_types#DC_CAL_DATE"
235!> variable that is saved in the "dc_calendar".
236!> When `date` is omitted in subsequent procedures, the internal date
237!> is used.
238!> If `date` is not omitted, the settings is stored to the `date`.
239!> In order to use the date setting, use the "dc_calendar_types#DC_CAL_DATE"
240!> variable to subsequent procedures.
241!>
242!> @param[in] date_str Strings that express date and time.
243!> See gtool4 netCDF Convention 5.5 Expression of date and time for details.
244!> @param[out] date An object that stores information of date and time.
245!> If this is omitted, these information is set as default date and time.
246!> @param[out] err Exception handling flag.
247!> By default, when error occur in this procedure, the program aborts.
248!> If this `err` argument is given, .true. is substituted to `err` and
249!> the program does not abort.
250!> @enden
251!>
252!> @ja
253!> @brief 日時文字列で日時を設定
254!> @details
255!> 日時の設定を行います.
256!>
257!> `date_str` に YYYY-MM-DDThh:mm:ss.sTZD の形式の文字列
258!> (YYYY は年, MM は月, DD は日, hh は時, mm は分, ss.s は秒,
259!> TZD はタイムゾーン) を指定してください.
260!> 年月日時分秒を各個変数で指定する場合には
261!> 上記の同名のサブルーチンを使用して下さい.
262!> 日時の文字列形式は
263!> gtool4 netCDF 規約「5.5 日時形式」に準拠しています.
264!>
265!> "s since 2009-06-17T11:23:45+09:00" のような文字列を与えた場合には,
266!> "s since " の部分をサブルーチン内で自動的に切り取って,
267!> "2009-06-17T11:23:45+09:00" の部分を設定します.
268!>
269!> 省略可能引数 `date` が省略された場合には, dc_calendar 内部で
270!> 保持される "dc_calendar_types#DC_CAL_DATE" 型の変数に日時が
271!> 設定されます. その後の手続きで `date` を省略した場合には
272!> この日時が使用されます.
273!> `date` が省略されない場合にはその変数に日時が設定されます.
274!> その日時を使用する場合, 手続きにその "dc_calendar_types#DC_CAL_DATE" 型の変数
275!> を与えてください.
276!>
277!> @param[in] date_str 日時情報を表す文字列.
278!> 表示形式については gtool4 netCDF 規約 5.5 日時形式を参照のこと.
279!> @param[out] date 日時情報を収めたオブジェクト.
280!> 省略した場合には, デフォルトの日時として指定される.
281!> @param[out] err 例外処理用フラグ.
282!> デフォルトでは, この手続き内でエラーが生じた場合,
283!> プログラムは強制終了します.
284!> 引数 `err` が与えられる場合, プログラムは強制終了せず,
285!> 代わりに `err` に .true. が代入されます.
286!> @endja
287subroutine dccaldatecreate2( date_str, date, err )
291 use dc_message, only: messagenotify
292 use dc_types, only: dp, token
293 use dc_trace, only: beginsub, endsub
295 use dc_types, only: string
296 implicit none
297 character(*), intent(in):: date_str
298 type(dc_cal_date), intent(out), optional, target:: date
299 logical, intent(out), optional:: err
300
301 ! 作業変数
302 ! Work variables
303 !
304 type(dc_cal_date), pointer:: datep =>null()
305 integer:: year
306 integer:: month
307 integer:: day
308 integer:: hour
309 integer:: min
310 real(DP):: sec
311 character(TOKEN):: zone
312 integer:: stat
313 character(STRING):: cause_c
314 character(*), parameter:: version = &
315 & '$Name: $' // &
316 & '$Id: dccaldatecreate.f90,v 1.3 2010-09-24 07:07:31 morikawa Exp $'
317 character(*), parameter:: subname = 'DCCalDateCreate2'
318continue
319 call beginsub( subname, version )
320 stat = dc_noerr
321 cause_c = ''
322
323 ! オブジェクトのポインタ割付
324 ! Associate pointer of an object
325 !
326 if ( present( date ) ) then
327 datep => date
328 else
329 datep => default_date
330 end if
331
332!!$ ! 初期設定のチェック
333!!$ ! Check initialization
334!!$ !
335!!$ if ( datep % initialized ) then
336!!$ stat = DC_EALREADYINIT
337!!$ cause_c = 'DC_CAL_DATE'
338!!$ goto 999
339!!$ end if
340
341 ! 日時を表現した文字列の解釈
342 ! Parse strings that express date and time
343 !
344 call dccaldateparsestr( date_str, & ! (in)
345 & year, month, day, hour, min, sec, zone, & ! (out)
346 & err = err ) ! (out) optional
347 if ( present(err) ) then
348 if ( err ) then
349 stat = dc_ebaddate
350 goto 999
351 end if
352 end if
353
354 ! オブジェクトの作成
355 ! Create an object
356 !
357 call dccaldatecreate( &
358 & year, month, day, hour, min, sec, & ! (in)
359 & datep, zone, err = err ) ! (out) optional
360 if ( present(err) ) then
361 if ( err ) then
362 stat = dc_ebaddate
363 goto 999
364 end if
365 end if
366
367 ! 終了処理, 例外処理
368 ! Termination and Exception handling
369 !
370999 continue
371 nullify( datep )
372 call storeerror( stat, subname, err, cause_c )
373 call endsub( subname )
374end subroutine dccaldatecreate2
subroutine dccaldatecreate2(date_str, date, err)
subroutine dccaldatecreate1(year, month, day, hour, min, sec, date, zone, err)
日時の設定手続
dc_calendar 手続のインターフェース宣言
dc_calendar用の内部モジュール
type(dc_cal_date), target, save, public default_date
デフォルトの日時. DCCalDate で始まる手続のうち, DC_CAL_DATE 型の省略可能引数が 与えられない場合にはこの日時が設定もしくは利用される.
暦と日時に関する構造データ型と定数
エラー処理用モジュール
Definition dc_error.f90:454
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition dc_error.f90:891
integer, parameter, public dc_noerr
エラー等を保持
Definition dc_error.f90:468
integer, parameter, public dc_ebaddate
Definition dc_error.f90:552
メッセージの出力
シンプルな正規表現関数 'match' を提供します.
Definition dc_regex.f90:62
subroutine, public match(pattern, text, start, length)
Definition dc_regex.f90:469
文字型変数の操作
Definition dc_string.f90:83
デバッグ時の追跡用モジュール
Definition dc_trace.f90:150
subroutine, public beginsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca, version)
Definition dc_trace.f90:457
subroutine, public endsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca)
Definition dc_trace.f90:580
種別型パラメタを提供します。
Definition dc_types.f90:55
integer, parameter, public token
単語やキーワードを保持する文字型変数の種別型パラメタ
Definition dc_types.f90:128
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition dc_types.f90:137
integer, parameter, public dp
倍精度実数型変数
Definition dc_types.f90:92