Loading...
Searching...
No Matches
dcunits_com.f90
Go to the documentation of this file.
1!== dcunits_com.f90 - 単位系処理用の下位モジュール
2!
3! Authors:: Eizi TOYODA, Yasuhiro MORIKAWA
4! Version:: $Id: dcunits_com.f90,v 1.2 2009-03-23 22:01:42 morikawa Exp $
5! Tag Name:: $Name: $
6! Copyright:: Copyright (C) GFD Dennou Club, 2000-2005. All rights reserved.
7! License:: See COPYRIGHT[link:../../COPYRIGHT]
8!
9! This file provides dcunits_com
10!
11
12module dcunits_com !:nodoc:
13 !
14 !== Overview
15 !
16 ! dc_units モジュールで用いる下位の定数およびサブルーチンを提供します。
17 !
18 ! common private data for dc_units module
19 !
20
21 use dc_types, only: dp, string
22 implicit none
23 private
27
28 ! scannter symbols
29 integer, parameter:: s_eof = -128
30 integer, parameter:: s_shift = 300
31 integer, parameter:: s_text = 301
32 integer, parameter:: s_multiply = 302
33 integer, parameter:: s_divide = 303
34 integer, parameter:: s_exponent = 304
35 integer, parameter:: s_openpar = 305
36 integer, parameter:: s_closepar = 306
37 integer, parameter:: s_real = 307
38 integer, parameter:: s_integer = 308
39
40 ! scanner buffer
41 character(STRING), private, save:: thisline = ""
42 integer, private, save:: i = 1
43
44contains
45
46 subroutine dcunitssetline(line)
47 implicit none
48 character(*), intent(in):: line
49 thisline = line
50 i = 1
51 end subroutine dcunitssetline
52
53 subroutine dcunitsgettoken(tokentype, ivalue, dvalue, cvalue)
54 use dc_regex, only: match
55 implicit none
56 integer, intent(out):: tokentype
57 integer, intent(out):: ivalue(5)
58 real(dp), intent(out):: dvalue
59 character(*), intent(out):: cvalue
60 integer:: iend, istr, ilen, ios
61 ivalue = 0
62 dvalue = 0.0_dp
63 cvalue = ""
64 iend = len_trim(thisline)
65 do
66 if (i > iend) exit
67 ! '#' 文字が現われれば EOF シンボルを返す
68 call match("^##", thisline(i:), istr, ilen)
69 if (istr > 0) then
70 i = iend + 1
71 tokentype = s_eof
72 return
73 endif
74 ! 空白を無視
75 call match("^#s+", thisline(i:), istr, ilen)
76 if (istr > 0) then
77 i = i + ilen
78 if (i > iend) exit
79 endif
80 ! シフト演算子チェック
81 call match("^@", thisline(i:), istr, ilen)
82 if (istr <= 0) call match("^from", thisline(i:), istr, ilen)
83 if (istr <= 0) call match("^at", thisline(i:), istr, ilen)
84 if (istr > 0) then
85 i = i + ilen
86 tokentype = s_shift
87 cvalue = thisline(i: i+ilen-1)
88 return
89 endif
90 ! 名前チェック
91 call match("^#a#w*#a", thisline(i:), istr, ilen)
92 if (istr <= 0) call match("^[#a'""]", thisline(i:), istr, ilen)
93 if (istr > 0) then
94 tokentype = s_text
95 cvalue = thisline(i: i+ilen-1)
96 i = i + ilen
97 return
98 endif
99 ! '*' の前に '**' を認知せねば。
100 call match("^#^", thisline(i:), istr, ilen)
101 if (istr <= 0) call match("^#*#*", thisline(i:), istr, ilen)
102 if (istr > 0) then
103 tokentype = s_exponent
104 cvalue = thisline(i: i+ilen-1)
105 i = i + ilen
106 return
107 endif
108 ! 実数にならない小数点は S_MULTIPLY
109 call match("^#.[^#d]", thisline(i:), istr, ilen)
110 if (istr <= 0) call match("^#*", thisline(i:), istr, ilen)
111 if (istr > 0) then
112 tokentype = s_multiply
113 cvalue = thisline(i: i+ilen-1)
114 i = i + 1
115 return
116 endif
117 ! 実数チェック. 小数点は語頭にあれば必ず数字が伴うので安心せよ
118 call match("^[-+]?#d*#.#d*[EeDd][-+]?#d+", thisline(i:), istr, ilen)
119 if (istr <= 0) call match("^[-+]?#d*#.#d*", thisline(i:), istr, ilen)
120 if (istr > 0) then
121 read(thisline(i: i+ilen-1), fmt=*, &
122 & iostat=ios) dvalue
123 if (ios /= 0) dvalue = huge(dvalue)
124 cvalue = thisline(i: i+ilen-1)
125 tokentype = s_real
126 i = i + ilen
127 return
128 endif
129 ! 整数チェック
130 call match("^[-+]?#d+", thisline(i:), istr, ilen)
131 if (istr > 0) then
132 read(thisline(i: i+ilen-1), fmt=*, &
133 & iostat=ios) ivalue(1)
134 if (ios /= 0) ivalue(1) = huge(1)
135 cvalue = thisline(i: i+ilen-1)
136 tokentype = s_integer
137 i = i + ilen
138 return
139 endif
140 ! ほかの1字トークンチェック
141 if (thisline(i:i) == '/') then
142 tokentype = s_divide
143 cvalue = thisline(i:i)
144 i = i + 1
145 return
146 endif
147 if (thisline(i:i) == '(') then
148 tokentype = s_openpar
149 cvalue = thisline(i:i)
150 i = i + 1
151 return
152 endif
153 if (thisline(i:i) == ')') then
154 tokentype = s_closepar
155 cvalue = thisline(i:i)
156 i = i + 1
157 return
158 endif
159 ! だめだこりゃ。はい次いってみよう
160 tokentype = ichar(thisline(i:i))
161 cvalue = thisline(i:i)
162 i = i + 1
163 return
164 enddo
165 i = iend + 1
166 tokentype = s_eof
167 cvalue = ""
168 end subroutine dcunitsgettoken
169
170end module dcunits_com
シンプルな正規表現関数 'match' を提供します.
Definition dc_regex.f90:16
subroutine, public match(pattern, text, start, length)
Definition dc_regex.f90:267
種別型パラメタを提供します。
Definition dc_types.f90:49
integer, parameter, public dp
倍精度実数型変数
Definition dc_types.f90:83
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition dc_types.f90:118
integer, parameter, public s_real
integer, parameter, public s_closepar
integer, parameter, public s_text
integer, parameter, public s_multiply
integer, parameter, public s_openpar
integer, parameter, public s_shift
integer, parameter, public s_integer
integer, parameter, public s_eof
subroutine, public dcunitsgettoken(tokentype, ivalue, dvalue, cvalue)
subroutine, public dcunitssetline(line)
integer, parameter, public s_exponent
integer, parameter, public s_divide