gtool5 Fortran 90/95 ライブラリ 1.0.0-rc5
English
Loading...
Searching...
No Matches
dccaldateparsestr.f90 File Reference

Go to the source code of this file.

Functions/Subroutines

subroutine dccaldateparsestr1 (date_str, year, month, day, hour, min, sec, zone, err)
 日時の文字列の解釈

Function/Subroutine Documentation

◆ dccaldateparsestr1()

subroutine dccaldateparsestr1 ( character(*), intent(in) date_str,
integer, intent(out) year,
integer, intent(out) month,
integer, intent(out) day,
integer, intent(out) hour,
integer, intent(out) min,
real(dp), intent(out) sec,
character(*), intent(out) zone,
logical, intent(out), optional err )

日時の文字列の解釈

Author
Yasuhiro MORIKAWA

このファイルに記載される手続き群は dc_calendar モジュールから提供されます.

日時文字列の解釈

date_str で与えられる日時形式 (gtool4 netCDF 規約「5.5 日時形式」に準拠) を解釈し, yearzone に返します.

Parameters
[in]date_str日時情報を表す文字列. 表示形式については gtool4 netCDF 規約 5.5 日時形式を参照のこと.
[out]year
[out]month
[out]day
[out]hour
[out]min
[out]sec
[out]zoneUTC からの時差
[out]err例外処理用フラグ. デフォルトでは, この手続き内でエラーが生じた場合, プログラムは強制終了します. 引数 err が与えられる場合, プログラムは強制終了せず, 代わりに err に .true. が代入されます.

Definition at line 66 of file dccaldateparsestr.f90.

69
70 use dc_regex, only: match
71 use dc_message, only: messagenotify
72 use dc_string, only: lchar, stoi, stod
75 use dc_types, only: string, dp, token
76 implicit none
77 character(*), intent(in):: date_str
78 integer, intent(out):: year
79 integer, intent(out):: month
80 integer, intent(out):: day
81 integer, intent(out):: hour
82 integer, intent(out):: min
83 real(DP), intent(out):: sec
84 character(*), intent(out):: zone
85 logical, intent(out), optional:: err
86
87 ! 作業変数
88 ! Work variables
89 !
90 integer:: start, length
91 character(STRING):: str1, str2
92 character(TOKEN):: zone_pm, zone_hrs, zone_min
93 integer:: stat
94 character(STRING):: cause_c
95 character(*), parameter:: subname = 'DCCalDateParseStr1'
96continue
97 call beginsub( subname )
98 stat = dc_noerr
99 cause_c = ''
100
101 ! 与えられた文字列が日時表現として有効かどうかをチェック
102 ! Check validation of strings as an expression of date
103 !
104 call match( '[-]*#d+-#d+-#d+[#w#s]+#d+:#d+:#d+', date_str, & ! (in)
105 & start, length ) ! (out)
106
107 if ( length > 0 ) then
108 str1 = date_str(start:)
109 else
110 stat = dc_ebaddate
111 call messagenotify('W', subname, &
112 & 'date_str=<%c> is invalid expression as date.', &
113 & c1 = trim(date_str) )
114 goto 999
115 end if
116
117 ! 年の解釈
118 ! Parse year
119 !
120 call match( '^[-]*#d+-', str1, & ! (in)
121 & start, length ) ! (out)
122 str2 = str1(start:start+length-2)
123 str1 = str1(start+length:)
124 year = stoi(str2)
125
126 ! 月の解釈
127 ! Parse month
128 !
129 call match( '^#d+-', str1, & ! (in)
130 & start, length ) ! (out)
131 str2 = str1(start:start+length-2)
132 str1 = str1(start+length:)
133 month = stoi(str2)
134
135 ! 日の解釈
136 ! Parse day
137 !
138 call match( '^#d+[#w#s]', str1, & ! (in)
139 & start, length ) ! (out)
140 str2 = str1(start:start+length-2)
141 str1 = str1(start+length:)
142 day = stoi(str2)
143
144 ! 時の解釈
145 ! Parse hour
146 !
147 call match( '#d+:', str1, & ! (in)
148 & start, length ) ! (out)
149 str2 = str1(start:start+length-2)
150 str1 = str1(start+length:)
151 hour = stoi(str2)
152
153 ! 分の解釈
154 ! Parse minute
155 !
156 call match( '#d+:', str1, & ! (in)
157 & start, length ) ! (out)
158 str2 = str1(start:start+length-2)
159 str1 = str1(start+length:)
160 min = stoi(str2)
161
162 ! 秒の解釈
163 ! Parse min
164 !
165 call match( '#d+', str1, & ! (in)
166 & start, length ) ! (out)
167 str2 = str1(start:start+length-1)
168 str1 = str1(start+length:)
169
170 call match( '^#.#d+', str1, & ! (in)
171 & start, length ) ! (out)
172
173 if ( length > 0 ) then
174 str2 = trim(str2) // str1(start:start+length-1)
175 str1 = str1(start+length:)
176 end if
177 sec = stod(str2)
178
179 ! UTC からの時差の解釈
180 ! Parse time-zone difference
181 !
182 call match( '[#+-]#d+:#d+', str1, & ! (in)
183 & start, length ) ! (out)
184 if ( length > 0 ) then
185 zone_pm = str1(start:start)
186 str1 = str1(start+1:start+length-1)
187
188 call match( '^#d+:', str1, & ! (in)
189 & start, length ) ! (out)
190 zone_hrs = str1(start:start+length-2)
191 zone_min = str1(start+length:)
192 zone = trim(zone_pm) // trim(zone_hrs) // ':' // trim(zone_min)
193 else
194 zone = ''
195 end if
196
197 call dbgmessage('year=<%d> month=<%d> day=<%d> hour=<%d> min=<%d> sec=<%f>' // &
198 & ' zone=<%c>', &
199 & i = (/year, month, day, hour, min/), d = (/sec/), &
200 & c1 = trim(zone) )
201
202 ! 終了処理, 例外処理
203 ! Termination and Exception handling
204 !
205999 continue
206 call storeerror( stat, subname, err, cause_c )
207 call endsub( subname )
エラー処理用モジュール
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 dbgmessage(fmt, i, r, d, l, n, c1, c2, c3, ca)
Definition dc_trace.f90:680
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
種別型パラメタを提供します。
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

References dc_trace::beginsub(), dc_trace::dbgmessage(), dc_error::dc_ebaddate, dc_error::dc_noerr, dc_types::dp, dc_trace::endsub(), dc_regex::match(), dc_error::storeerror(), dc_types::string, and dc_types::token.

Here is the call graph for this function: