gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
Functions/Subroutines | Variables
dcunits_com Module Reference

Internal module for dc_units. More...

Functions/Subroutines

subroutine, public dcunitssetline (line)
 
subroutine, public dcunitsgettoken (tokentype, ivalue, dvalue, cvalue)
 

Variables

integer, parameter, public s_eof = -128
 End of file/string symbol
 
integer, parameter, public s_shift = 300
 Shift operator symbol
 
integer, parameter, public s_text = 301
 Text/name token symbol
 
integer, parameter, public s_multiply = 302
 Multiply operator symbol
 
integer, parameter, public s_divide = 303
 Divide operator symbol
 
integer, parameter, public s_exponent = 304
 Exponent operator symbol
 
integer, parameter, public s_openpar = 305
 Open parenthesis symbol
 
integer, parameter, public s_closepar = 306
 Close parenthesis symbol
 
integer, parameter, public s_real = 307
 Real number symbol
 
integer, parameter, public s_integer = 308
 Integer number symbol
 

Detailed Description

Internal module for dc_units.

Author
Eizi TOYODA, Yasuhiro MORIKAWA

Function/Subroutine Documentation

◆ dcunitsgettoken()

subroutine, public dcunits_com::dcunitsgettoken ( integer, intent(out)  tokentype,
integer, dimension(5), intent(out)  ivalue,
real(dp), intent(out)  dvalue,
character(*), intent(out)  cvalue 
)

Get next token from input line

Scans the input line and returns the next token. Token types include operators, numbers, and text.

Parameters
[out]tokentypeType of the token (S_EOF, S_TEXT, etc.)
[out]ivalueInteger values array (for integer tokens)
[out]dvalueReal value (for real number tokens)
[out]cvalueCharacter value (token string)

Definition at line 172 of file dcunits_com.f90.

173 use dc_regex, only: match
174 implicit none
175 integer, intent(out):: tokentype
176 integer, intent(out):: ivalue(5)
177 real(DP), intent(out):: dvalue
178 character(*), intent(out):: cvalue
179 integer:: iend, istr, ilen, ios
180 ivalue = 0
181 dvalue = 0.0_dp
182 cvalue = ""
183 iend = len_trim(thisline)
184 do
185 if (i > iend) exit
186 ! '#' 文字が現われれば EOF シンボルを返す
187 call match("^##", thisline(i:), istr, ilen)
188 if (istr > 0) then
189 i = iend + 1
190 tokentype = s_eof
191 return
192 endif
193 ! 空白を無視
194 call match("^#s+", thisline(i:), istr, ilen)
195 if (istr > 0) then
196 i = i + ilen
197 if (i > iend) exit
198 endif
199 ! シフト演算子チェック
200 call match("^@", thisline(i:), istr, ilen)
201 if (istr <= 0) call match("^from", thisline(i:), istr, ilen)
202 if (istr <= 0) call match("^at", thisline(i:), istr, ilen)
203 if (istr > 0) then
204 i = i + ilen
205 tokentype = s_shift
206 cvalue = thisline(i: i+ilen-1)
207 return
208 endif
209 ! 名前チェック
210 call match("^#a#w*#a", thisline(i:), istr, ilen)
211 if (istr <= 0) call match("^[#a'""]", thisline(i:), istr, ilen)
212 if (istr > 0) then
213 tokentype = s_text
214 cvalue = thisline(i: i+ilen-1)
215 i = i + ilen
216 return
217 endif
218 ! '*' の前に '**' を認知せねば。
219 call match("^#^", thisline(i:), istr, ilen)
220 if (istr <= 0) call match("^#*#*", thisline(i:), istr, ilen)
221 if (istr > 0) then
222 tokentype = s_exponent
223 cvalue = thisline(i: i+ilen-1)
224 i = i + ilen
225 return
226 endif
227 ! 実数にならない小数点は S_MULTIPLY
228 call match("^#.[^#d]", thisline(i:), istr, ilen)
229 if (istr <= 0) call match("^#*", thisline(i:), istr, ilen)
230 if (istr > 0) then
231 tokentype = s_multiply
232 cvalue = thisline(i: i+ilen-1)
233 i = i + 1
234 return
235 endif
236 ! 実数チェック. 小数点は語頭にあれば必ず数字が伴うので安心せよ
237 call match("^[-+]?#d*#.#d*[EeDd][-+]?#d+", thisline(i:), istr, ilen)
238 if (istr <= 0) call match("^[-+]?#d*#.#d*", thisline(i:), istr, ilen)
239 if (istr > 0) then
240 read(thisline(i: i+ilen-1), fmt=*, &
241 & iostat=ios) dvalue
242 if (ios /= 0) dvalue = huge(dvalue)
243 cvalue = thisline(i: i+ilen-1)
244 tokentype = s_real
245 i = i + ilen
246 return
247 endif
248 ! 整数チェック
249 call match("^[-+]?#d+", thisline(i:), istr, ilen)
250 if (istr > 0) then
251 read(thisline(i: i+ilen-1), fmt=*, &
252 & iostat=ios) ivalue(1)
253 if (ios /= 0) ivalue(1) = huge(1)
254 cvalue = thisline(i: i+ilen-1)
255 tokentype = s_integer
256 i = i + ilen
257 return
258 endif
259 ! ほかの1字トークンチェック
260 if (thisline(i:i) == '/') then
261 tokentype = s_divide
262 cvalue = thisline(i:i)
263 i = i + 1
264 return
265 endif
266 if (thisline(i:i) == '(') then
267 tokentype = s_openpar
268 cvalue = thisline(i:i)
269 i = i + 1
270 return
271 endif
272 if (thisline(i:i) == ')') then
273 tokentype = s_closepar
274 cvalue = thisline(i:i)
275 i = i + 1
276 return
277 endif
278 ! だめだこりゃ。はい次いってみよう
279 tokentype = ichar(thisline(i:i))
280 cvalue = thisline(i:i)
281 i = i + 1
282 return
283 enddo
284 i = iend + 1
285 tokentype = s_eof
286 cvalue = ""
Provides simple regular expression subroutine: 'match'.
Definition dc_regex.f90:62
subroutine, public match(pattern, text, start, length)
Definition dc_regex.f90:469

References dc_regex::match(), s_closepar, s_divide, s_eof, s_exponent, s_integer, s_multiply, s_openpar, s_real, s_shift, and s_text.

Here is the call graph for this function:

◆ dcunitssetline()

subroutine, public dcunits_com::dcunitssetline ( character(*), intent(in)  line)

Set input line for scanner

Sets the input line to be scanned and resets the scanner position.

Parameters
[in]lineInput line to scan

Definition at line 142 of file dcunits_com.f90.

143 implicit none
144 character(*), intent(in):: line
145 thisline = line
146 i = 1

Variable Documentation

◆ s_closepar

dcunits_com::s_closepar = 306

Close parenthesis symbol

Definition at line 103 of file dcunits_com.f90.

103 integer, parameter:: S_CLOSEPAR = 306

◆ s_divide

dcunits_com::s_divide = 303

Divide operator symbol

Definition at line 88 of file dcunits_com.f90.

88 integer, parameter:: S_DIVIDE = 303

◆ s_eof

dcunits_com::s_eof = -128

End of file/string symbol

Definition at line 68 of file dcunits_com.f90.

68 integer, parameter:: S_EOF = -128

◆ s_exponent

dcunits_com::s_exponent = 304

Exponent operator symbol

Definition at line 93 of file dcunits_com.f90.

93 integer, parameter:: S_EXPONENT = 304

◆ s_integer

dcunits_com::s_integer = 308

Integer number symbol

Definition at line 113 of file dcunits_com.f90.

113 integer, parameter:: S_INTEGER = 308

◆ s_multiply

dcunits_com::s_multiply = 302

Multiply operator symbol

Definition at line 83 of file dcunits_com.f90.

83 integer, parameter:: S_MULTIPLY = 302

◆ s_openpar

dcunits_com::s_openpar = 305

Open parenthesis symbol

Definition at line 98 of file dcunits_com.f90.

98 integer, parameter:: S_OPENPAR = 305

◆ s_real

dcunits_com::s_real = 307

Real number symbol

Definition at line 108 of file dcunits_com.f90.

108 integer, parameter:: S_REAL = 307

◆ s_shift

dcunits_com::s_shift = 300

Shift operator symbol

Definition at line 73 of file dcunits_com.f90.

73 integer, parameter:: S_SHIFT = 300

◆ s_text

dcunits_com::s_text = 301

Text/name token symbol

Definition at line 78 of file dcunits_com.f90.

78 integer, parameter:: S_TEXT = 301