gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
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)
 Parse strings of date.

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 )

Parse strings of date.

Author
Yasuhiro MORIKAWA

Procedures described in this file are provided from "dc_calendar" module.

Parse date string

Parse strings of date (conformed to gtool4 netCDF Convention "5.5 Expression of date and time") specified as date_str, and return yearzone.

Parameters
[in]date_strStrings that express date and time. See gtool4 netCDF Convention 5.5 Expression of date and time for details.
[out]yearYear
[out]monthMonth
[out]dayDay
[out]hourHour
[out]minMinute
[out]secSecond
[out]zoneTime-zone (difference from UTC)
[out]errException handling flag. By default, when error occur in this procedure, the program aborts. If this err argument is given, .true. is substituted to err and the program does not abort.

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 )
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_noerr
Error storage variables
Definition dc_error.f90:468
integer, parameter, public dc_ebaddate
Definition dc_error.f90:552
Message output module.
Provides simple regular expression subroutine: 'match'.
Definition dc_regex.f90:62
subroutine, public match(pattern, text, start, length)
Definition dc_regex.f90:469
Handling character types.
Definition dc_string.f90:83
Debug tracing module.
Definition dc_trace.f90:150
subroutine, public dbgmessage(fmt, i, r, d, l, n, c1, c2, c3, ca)
Definition dc_trace.f90:661
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
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

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: