carray 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (231) hide show
  1. checksums.yaml +4 -4
  2. data/COPYING +56 -0
  3. data/GPL +340 -0
  4. data/Gemfile +9 -0
  5. data/Gemfile.lock +33 -0
  6. data/LEGAL +50 -0
  7. data/NOTE +73 -0
  8. data/Rakefile +20 -0
  9. data/TODO +5 -0
  10. data/ca_iter_block.c +242 -0
  11. data/ca_iter_dimension.c +287 -0
  12. data/ca_iter_window.c +202 -0
  13. data/ca_obj_array.c +1189 -0
  14. data/ca_obj_bitarray.c +523 -0
  15. data/ca_obj_bitfield.c +636 -0
  16. data/ca_obj_block.c +885 -0
  17. data/ca_obj_fake.c +405 -0
  18. data/ca_obj_farray.c +482 -0
  19. data/ca_obj_field.c +625 -0
  20. data/ca_obj_grid.c +738 -0
  21. data/ca_obj_mapping.c +614 -0
  22. data/ca_obj_object.c +777 -0
  23. data/ca_obj_reduce.c +299 -0
  24. data/ca_obj_refer.c +627 -0
  25. data/ca_obj_repeat.c +640 -0
  26. data/ca_obj_select.c +558 -0
  27. data/ca_obj_shift.c +952 -0
  28. data/ca_obj_transpose.c +582 -0
  29. data/ca_obj_unbound_repeat.c +557 -0
  30. data/ca_obj_window.c +1023 -0
  31. data/carray.h +1381 -0
  32. data/carray_access.c +1798 -0
  33. data/carray_attribute.c +903 -0
  34. data/carray_call_cfunc.c +1107 -0
  35. data/carray_cast.c +1155 -0
  36. data/carray_cast_func.rb +498 -0
  37. data/carray_class.c +132 -0
  38. data/carray_conversion.c +518 -0
  39. data/carray_copy.c +453 -0
  40. data/carray_core.c +1307 -0
  41. data/carray_element.c +572 -0
  42. data/carray_generate.c +681 -0
  43. data/carray_iterator.c +630 -0
  44. data/carray_loop.c +462 -0
  45. data/carray_mask.c +1174 -0
  46. data/carray_math.rb +834 -0
  47. data/carray_numeric.c +257 -0
  48. data/carray_operator.c +582 -0
  49. data/carray_order.c +1040 -0
  50. data/carray_random.c +529 -0
  51. data/carray_sort_addr.c +261 -0
  52. data/carray_stat.c +2102 -0
  53. data/carray_stat_proc.rb +1990 -0
  54. data/carray_test.c +602 -0
  55. data/carray_undef.c +69 -0
  56. data/carray_utils.c +740 -0
  57. data/ext/calculus/carray_calculus.c +792 -0
  58. data/ext/calculus/carray_interp.c +355 -0
  59. data/ext/calculus/extconf.rb +12 -0
  60. data/ext/calculus/lib/autoload/autoload_math_calculus.rb +2 -0
  61. data/ext/calculus/lib/math/calculus.rb +119 -0
  62. data/ext/calculus/lib/math/interp/adapter_interp1d.rb +31 -0
  63. data/ext/dataframe/API.txt +11 -0
  64. data/ext/dataframe/extconf.rb +3 -0
  65. data/ext/dataframe/lib/carray/autoload/autoload_dataframe_dataframe.rb +14 -0
  66. data/ext/dataframe/lib/carray/dataframe/dataframe.rb +1104 -0
  67. data/ext/dataframe/sample/test_uniq_sort.rb +5 -0
  68. data/ext/fortio/extconf.rb +3 -0
  69. data/ext/fortio/lib/carray/autoload/autoload_fortran_format.rb +5 -0
  70. data/ext/fortio/lib/carray/io/fortran_format.rb +43 -0
  71. data/ext/fortio/lib/fortio.rb +3 -0
  72. data/ext/fortio/lib/fortio/fortran_format.rb +603 -0
  73. data/ext/fortio/lib/fortio/fortran_format.tab.rb +536 -0
  74. data/ext/fortio/lib/fortio/fortran_format.y +215 -0
  75. data/ext/fortio/lib/fortio/fortran_namelist.rb +151 -0
  76. data/ext/fortio/lib/fortio/fortran_namelist.tab.rb +470 -0
  77. data/ext/fortio/lib/fortio/fortran_namelist.y +213 -0
  78. data/ext/fortio/lib/fortio/fortran_sequential.rb +345 -0
  79. data/ext/fortio/ruby_fortio.c +182 -0
  80. data/ext/fortio/test/test_H.rb +5 -0
  81. data/ext/fortio/test/test_T.rb +7 -0
  82. data/ext/fortio/test/test_fortran_format.rb +86 -0
  83. data/ext/fortio/test/test_namelist.rb +25 -0
  84. data/ext/fortio/test/test_sequential.rb +13 -0
  85. data/ext/fortio/test/test_sequential2.rb +13 -0
  86. data/ext/fortio/work/test.rb +10 -0
  87. data/ext/fortio/work/test_e.rb +19 -0
  88. data/ext/fortio/work/test_ep.rb +10 -0
  89. data/ext/fortio/work/test_parse.rb +12 -0
  90. data/ext/imagemap/carray_imagemap.c +495 -0
  91. data/ext/imagemap/doc/call_graph.dot +28 -0
  92. data/ext/imagemap/draw.c +567 -0
  93. data/ext/imagemap/extconf.rb +13 -0
  94. data/ext/imagemap/lib/autoload/autoload_graphics_imagemap.rb +1 -0
  95. data/ext/imagemap/lib/graphics/imagemap.rb +273 -0
  96. data/ext/imagemap/lib/image_map.rb +4 -0
  97. data/ext/imagemap/test/swath_index.rb +83 -0
  98. data/ext/imagemap/test/swath_warp.rb +99 -0
  99. data/ext/imagemap/test/test.rb +23 -0
  100. data/ext/imagemap/test/test_image.rb +42 -0
  101. data/ext/imagemap/test/test_line.rb +14 -0
  102. data/ext/imagemap/test/test_rotate.rb +17 -0
  103. data/ext/imagemap/test/test_triangle.rb +20 -0
  104. data/ext/imagemap/test/test_warp.rb +26 -0
  105. data/ext/mathfunc/carray_mathfunc.c +321 -0
  106. data/ext/mathfunc/extconf.rb +18 -0
  107. data/ext/mathfunc/lib/autoload/autoload_math_mathfunc.rb +1 -0
  108. data/ext/mathfunc/lib/math/mathfunc.rb +15 -0
  109. data/ext/mathfunc/test/test_hypot.rb +5 -0
  110. data/ext/mathfunc/test/test_j0.rb +22 -0
  111. data/ext/mathfunc/test/test_jn.rb +8 -0
  112. data/ext/mathfunc/test/test_sph.rb +9 -0
  113. data/ext/narray/README +22 -0
  114. data/ext/narray/ca_wrap_narray.c +491 -0
  115. data/ext/narray/carray_narray.c +21 -0
  116. data/ext/narray/extconf.rb +57 -0
  117. data/ext/narray/lib/autoload/autoload_math_narray.rb +1 -0
  118. data/ext/narray/lib/autoload/autoload_math_narray_miss.rb +11 -0
  119. data/ext/narray/lib/math/narray.rb +17 -0
  120. data/ext/narray/lib/math/narray_miss.rb +45 -0
  121. data/extconf.rb +3 -25
  122. data/lib/carray.rb +28 -0
  123. data/lib/carray/autoload/autoload_base.rb +23 -0
  124. data/lib/carray/autoload/autoload_graphics_gnuplot.rb +2 -0
  125. data/lib/carray/autoload/autoload_io_csv.rb +14 -0
  126. data/lib/carray/autoload/autoload_io_excel.rb +5 -0
  127. data/lib/carray/autoload/autoload_io_imagemagick.rb +6 -0
  128. data/lib/carray/autoload/autoload_io_pg.rb +6 -0
  129. data/lib/carray/autoload/autoload_io_sqlite3.rb +12 -0
  130. data/lib/carray/autoload/autoload_io_table.rb +1 -0
  131. data/lib/carray/autoload/autoload_math_histogram.rb +5 -0
  132. data/lib/carray/autoload/autoload_math_interp.rb +4 -0
  133. data/lib/carray/autoload/autoload_math_recurrence.rb +6 -0
  134. data/lib/carray/autoload/autoload_object_iterator.rb +1 -0
  135. data/lib/carray/autoload/autoload_object_link.rb +1 -0
  136. data/lib/carray/autoload/autoload_object_pack.rb +2 -0
  137. data/lib/carray/base/autoload.rb +94 -0
  138. data/lib/carray/base/basic.rb +1051 -0
  139. data/lib/carray/base/inspect.rb +252 -0
  140. data/lib/carray/base/iterator.rb +367 -0
  141. data/lib/carray/base/math.rb +403 -0
  142. data/lib/carray/base/obsolete.rb +93 -0
  143. data/lib/carray/base/serialize.rb +260 -0
  144. data/lib/carray/base/struct.rb +634 -0
  145. data/lib/carray/graphics/gnuplot.rb +2116 -0
  146. data/lib/carray/info.rb +112 -0
  147. data/lib/carray/io/csv.rb +560 -0
  148. data/lib/carray/io/excel.rb +26 -0
  149. data/lib/carray/io/imagemagick.rb +231 -0
  150. data/lib/carray/io/pg.rb +101 -0
  151. data/lib/carray/io/sqlite3.rb +202 -0
  152. data/lib/carray/io/table.rb +77 -0
  153. data/lib/carray/math/histogram.rb +179 -0
  154. data/lib/carray/math/interp.rb +57 -0
  155. data/lib/carray/math/interp/adapter_gsl_spline.rb +47 -0
  156. data/lib/carray/math/recurrence.rb +95 -0
  157. data/lib/carray/mkmf.rb +145 -0
  158. data/lib/carray/object/ca_obj_iterator.rb +52 -0
  159. data/lib/carray/object/ca_obj_link.rb +52 -0
  160. data/lib/carray/object/ca_obj_pack.rb +101 -0
  161. data/mkmath.rb +731 -0
  162. data/mt19937ar.c +182 -0
  163. data/mt19937ar.h +86 -0
  164. data/rdoc_main.rb +27 -0
  165. data/rdoc_math.rb +5 -0
  166. data/rdoc_stat.rb +31 -0
  167. data/ruby_carray.c +242 -0
  168. data/ruby_ccomplex.c +497 -0
  169. data/ruby_float_func.c +83 -0
  170. data/spec/CABlockIterator/CABlockIterator_spec.rb +113 -0
  171. data/spec/CArray/bug/store_spec.rb +27 -0
  172. data/spec/CArray/index/repeat_spec.rb +10 -0
  173. data/spec/CArray/method/eq_spec.rb +80 -0
  174. data/spec/CArray/method/is_nan_spec.rb +12 -0
  175. data/spec/CArray/method/ne_spec.rb +18 -0
  176. data/spec/CArray/method/round_spec.rb +11 -0
  177. data/spec/CArray/object/_attribute_spec.rb +32 -0
  178. data/spec/CArray/object/s_new_spec.rb +31 -0
  179. data/spec/CArray/serialize/Serialization_spec.rb +89 -0
  180. data/spec/spec_all.rb +11 -0
  181. data/test/test_ALL.rb +50 -0
  182. data/test/test_CABitfield.rb +59 -0
  183. data/test/test_CABlock.rb +208 -0
  184. data/test/test_CAField.rb +40 -0
  185. data/test/test_CAGrid.rb +76 -0
  186. data/test/test_CAMapping.rb +106 -0
  187. data/test/test_CAMmap.rb +11 -0
  188. data/test/test_CARefer.rb +94 -0
  189. data/test/test_CARepeat.rb +66 -0
  190. data/test/test_CASelect.rb +23 -0
  191. data/test/test_CAShift.rb +17 -0
  192. data/test/test_CATranspose.rb +61 -0
  193. data/test/test_CAVirtual.rb +214 -0
  194. data/test/test_CAWindow.rb +55 -0
  195. data/test/test_CAWrap.rb +9 -0
  196. data/test/test_CArray.rb +228 -0
  197. data/test/test_CComplex.rb +83 -0
  198. data/test/test_CScalar.rb +91 -0
  199. data/test/test_attribute.rb +281 -0
  200. data/test/test_block_iterator.rb +17 -0
  201. data/test/test_boolean.rb +99 -0
  202. data/test/test_cast.rb +33 -0
  203. data/test/test_class.rb +85 -0
  204. data/test/test_complex.rb +43 -0
  205. data/test/test_composite.rb +125 -0
  206. data/test/test_convert.rb +79 -0
  207. data/test/test_copy.rb +141 -0
  208. data/test/test_creation.rb +85 -0
  209. data/test/test_element.rb +146 -0
  210. data/test/test_extream.rb +55 -0
  211. data/test/test_generate.rb +75 -0
  212. data/test/test_index.rb +71 -0
  213. data/test/test_mask.rb +578 -0
  214. data/test/test_math.rb +98 -0
  215. data/test/test_narray.rb +64 -0
  216. data/test/test_order.rb +147 -0
  217. data/test/test_random.rb +15 -0
  218. data/test/test_ref_store.rb +211 -0
  219. data/test/test_stat.rb +414 -0
  220. data/test/test_struct.rb +72 -0
  221. data/test/test_virtual.rb +49 -0
  222. data/utils/ca_ase.rb +21 -0
  223. data/utils/ca_methods.rb +15 -0
  224. data/utils/cast_checker.rb +30 -0
  225. data/utils/create_rdoc.sh +9 -0
  226. data/utils/diff_method.rb +52 -0
  227. data/utils/extract_rdoc.rb +27 -0
  228. data/utils/make_tgz.sh +3 -0
  229. data/utils/remove_resource_fork.sh +5 -0
  230. data/version.h +3 -3
  231. metadata +266 -1
@@ -0,0 +1,215 @@
1
+ # ----------------------------------------------------------------------------
2
+ #
3
+ # carray/io/fortran_format.y
4
+ #
5
+ # This file is part of Ruby/CArray extension library.
6
+ # You can redistribute it and/or modify it under the terms of
7
+ # the Ruby Licence.
8
+ #
9
+ # Copyright (C) 2005 Hiroki Motoyoshi
10
+ #
11
+ # ----------------------------------------------------------------------------
12
+
13
+ #
14
+ # racc fortran_format.y -> fortan_format.tab.rb
15
+ #
16
+
17
+ class FortranFormatParser
18
+
19
+ rule
20
+
21
+ format :
22
+ format_string {
23
+ if val[0].size == 1 and val[0].first.is_a?(Group)
24
+ result = val[0].first
25
+ else
26
+ result = Group.new(1,val[0])
27
+ end
28
+ }
29
+
30
+ format_string :
31
+ format_spec { result = [val[0]] }
32
+ | format_string format_spec
33
+ { result = val[0] + [val[1]] }
34
+
35
+ format_spec :
36
+ hollerith { result = val[0] }
37
+ | unrepeatable { result = val[0] }
38
+ | repeatable { result = val[0] }
39
+ | DIGITS repeatable
40
+ { val[1].count = val[0]; result = val[1] }
41
+
42
+ hollerith : H { result = NodeH.new(*val[0]) }
43
+
44
+ unrepeatable :
45
+ STRING { result = NodeS.new(val[0]) }
46
+ | P { result = NodeP.new(val[0]) }
47
+ | Sp { result = NodeSp.new(val[0]) }
48
+ | B { result = NodeB.new(val[0]) }
49
+ | T { result = NodeT.new(val[0]) }
50
+ | TR { result = NodeTR.new(val[0]) }
51
+ | TL { result = NodeTL.new(val[0]) }
52
+ | '$' { result = Continue.new }
53
+
54
+ repeatable :
55
+ '(' format_string ')'
56
+ { result = Group.new(1,val[1]) }
57
+ | fixed_point
58
+ | floating_point
59
+ | '/' { result = Flush.new(1) }
60
+
61
+ fixed_point :
62
+ X { result = NodeX.new(1) }
63
+ | A { result = NodeA.new(1, val[0]) }
64
+ | I { result = NodeI.new(1, *val[0]) }
65
+ | L { result = NodeL.new(1, *val[0]) }
66
+ | F { result = NodeF.new(1, *val[0]) }
67
+
68
+ floating_point :
69
+ E { result = NodeE.new(1, *val[0]) }
70
+ | ES { result = NodeES.new(1, *val[0]) }
71
+ | D { result = NodeE.new(1, *val[0]) }
72
+ | G { result = NodeG.new(1, *val[0]) }
73
+ | floating_point EXP
74
+ { result = val[0]; result.exp = val[1] }
75
+
76
+ end
77
+
78
+ ---- inner
79
+
80
+ def parse (str)
81
+ @scan = FortranFormatScanner.new(str)
82
+ @scale = 0
83
+ @continue = false
84
+ do_parse
85
+ end
86
+
87
+ def next_token
88
+ return @scan.yylex
89
+ end
90
+
91
+ ---- header
92
+
93
+ require "strscan"
94
+
95
+ class FortranFormatScanner
96
+
97
+ def initialize (text)
98
+ @s = StringScanner.new(text)
99
+ end
100
+
101
+ def yylex
102
+ while @s.rest?
103
+ case
104
+ when @s.scan(/\A(ES|[FEDG])(\d+)\.(\d+)/i) ### {F|E|D|G|ES}w.d
105
+ return [
106
+ @s[1].upcase.to_sym,
107
+ [
108
+ @s[2].to_i,
109
+ @s[3].to_i
110
+ ]
111
+ ]
112
+ when @s.scan(/\AE(\d+)/i) ### Ed (for exponential)
113
+ return [
114
+ :EXP,
115
+ @s[1].to_i
116
+ ]
117
+ when @s.scan(/\AI(\d+)(\.(\d+))?/i) ### Iw(.d)
118
+ return [
119
+ :I,
120
+ [
121
+ @s[1].to_i,
122
+ @s[3] ? @s[3].to_i : nil
123
+ ]
124
+ ]
125
+ when @s.scan(/\AL(\d+)?/i) ### L(w)
126
+ return [
127
+ :L,
128
+ @s[1] ? @s[1].to_i : nil
129
+ ]
130
+ when @s.scan(/\AA(\d+)?/i) ### A(w)
131
+ return [
132
+ :A,
133
+ @s[1] ? @s[1].to_i : nil
134
+ ]
135
+ when @s.scan(/\AX/i) ### X
136
+ return [
137
+ :X,
138
+ nil
139
+ ]
140
+ when @s.scan(/\ATL(\d+)?/i) ### TLw
141
+ return [
142
+ :TL,
143
+ @s[1] ? @s[1].to_i : 1
144
+ ]
145
+ when @s.scan(/\ATR(\d+)?/i) ### TRw
146
+ return [
147
+ :TR,
148
+ @s[1] ? @s[1].to_i : 1
149
+ ]
150
+ when @s.scan(/\AT(\d+)?/i) ### Tw
151
+ return [
152
+ :T,
153
+ @s[1] ? @s[1].to_i : 1
154
+ ]
155
+ when @s.scan(/\A([+-]?\d+)P/i) ### {+|-|}P
156
+ return [
157
+ :P,
158
+ @s[1].to_i
159
+ ]
160
+ when @s.scan(/\AS[PS]?/i) ### S,SP,SS
161
+ return [
162
+ :Sp,
163
+ @s[0] =~ /SP/i ? true : false
164
+ ]
165
+ when @s.scan(/\AB[NZ]/i) ### BN,BZ
166
+ return [
167
+ :B,
168
+ @s[0] =~ /BZ/i ? true : false
169
+ ]
170
+ when @s.match?(/\A(\d+)?H/i) ### Hollerith
171
+ count = @s[1] ? @s[1].to_i : 1
172
+ if @s.scan(/\A(\d+)?H(.{#{count}})/)
173
+ return [
174
+ :H,
175
+ [count, @s[2]]
176
+ ]
177
+ else
178
+ raise "invalid horeris descriptor"
179
+ end
180
+ when @s.scan(/\A'((?:''|[^'])*)'/) ### 'quoted string'
181
+ return [
182
+ :STRING,
183
+ @s[1].gsub(/''/, "'")
184
+ ]
185
+ when @s.scan(/\A"((?:""|[^"])*)"/) ### 'double-quoted string'
186
+ return [
187
+ :STRING,
188
+ @s[1].gsub(/""/, '"')
189
+ ]
190
+ when @s.scan(/\A(\d+)/) ### digits
191
+ return [
192
+ :DIGITS,
193
+ @s[1].to_i
194
+ ]
195
+ when @s.scan(/\A([\(\)\/\$\:])/) ### {(|)|/|$}
196
+ return [
197
+ @s[1],
198
+ nil
199
+ ]
200
+ when @s.scan(/:/)
201
+ raise("format descriptor ':' is not supported.")
202
+ when @s.scan(/\A,/) ### blank
203
+ next
204
+ when @s.scan(/\A\s+/) ### blank
205
+ next
206
+ else
207
+ raise "FortranFormat parse error\n\t#{@s.string}\n\t#{' '*@s.pos}^"
208
+ end
209
+ end
210
+ end
211
+
212
+ end
213
+
214
+ ---- footer
215
+
@@ -0,0 +1,151 @@
1
+ # ----------------------------------------------------------------------------
2
+ #
3
+ # carray/io/fortran_namelist.rb
4
+ #
5
+ # This file is part of Ruby/CArray extension library.
6
+ # You can redistribute it and/or modify it under the terms of
7
+ # the Ruby Licence.
8
+ #
9
+ # Copyright (C) 2005 Hiroki Motoyoshi
10
+ #
11
+ # ----------------------------------------------------------------------------
12
+
13
+ require "carray"
14
+ require "fortio/fortran_namelist.tab"
15
+
16
+ class FortranNamelistReader
17
+
18
+ def initialize (text)
19
+ @namelist = FortranNamelistParser.new.parse(text)
20
+ end
21
+
22
+ def read (name, out={})
23
+ name = name.downcase
24
+ unless nml = @namelist[name]
25
+ raise "no definition of namelist '#{name}'"
26
+ end
27
+ nml.each do |paramdef|
28
+ paramdef.set(out)
29
+ end
30
+ return out
31
+ end
32
+
33
+ def read_all
34
+ all = {}
35
+ @namelist.each do |name, nml|
36
+ all[name] = {}
37
+ read(name, all[name])
38
+ end
39
+ return all
40
+ end
41
+
42
+ attr_reader :namelist
43
+
44
+ end
45
+
46
+ def fortran_namelist (name, out)
47
+ list = out.map{ |ident, value|
48
+ case value
49
+ when CArray
50
+ ident = "#{ident}(" + value.dim.map{|d| "1:#{d}" }.join(",") + ")"
51
+ value = value.flatten.to_a.join(",")
52
+ when Array
53
+ value = value.flatten.join(",")
54
+ when String
55
+ if value !~ /'/
56
+ value = "'" + value + "'"
57
+ else
58
+ value = '"' + value.gsub(/"/, '""') + '"'
59
+ end
60
+ when Float
61
+ value = value.to_s.sub(/e/, "d")
62
+ end
63
+ " #{ident} = #{value}"
64
+ }
65
+ return ["&#{name}", list.join(",\n") + " /"].join("\n")
66
+ end
67
+
68
+ def fortran_namelist_read (io, name=nil, out={})
69
+ case io
70
+ when String
71
+ text = io
72
+ else
73
+ text = io.read
74
+ end
75
+ if name
76
+ return FortranNamelistReader.new(text).read(name, out)
77
+ else
78
+ return FortranNamelistReader.new(text).read_all()
79
+ end
80
+ end
81
+
82
+ def fortran_namelist_write (io, name, out)
83
+ io << fortran_namelist(name, out)
84
+ return io
85
+ end
86
+
87
+ class FortranNamelistParser
88
+
89
+ ParamDef = Struct.new(:ident, :array_spec, :rval)
90
+ class ParamDef
91
+ def set (hash)
92
+ case hash[ident]
93
+ when CArray
94
+ hash[ident].attach { |ca|
95
+ if array_spec
96
+ crv = rval.to_ca
97
+ if crv.search(nil)
98
+ mask = crv.ne(nil)
99
+ ca[*array_spec][0...crv.size][mask] = crv[mask]
100
+ elsif ca[*array_spec].is_a?(CArray)
101
+ ca[*array_spec][0...crv.size] = crv
102
+ else
103
+ ca[*array_spec] = rval.first
104
+ end
105
+ else
106
+ if rval.is_a?(Array) and rval.size == 1
107
+ ca[0] = rval.first
108
+ else
109
+ ca[0...rval.size] = rval
110
+ end
111
+ end
112
+ }
113
+ when Array
114
+ if array_spec
115
+ if array_spec.first.is_a?(Integer) and rval.size == 1
116
+ hash[ident][*array_spec] = rval.first
117
+ else
118
+ hash[ident][*array_spec] = rval.first
119
+ end
120
+ else
121
+ if rval.is_a?(Array) and rval.size == 1
122
+ hash[ident][0] = rval.first
123
+ else
124
+ hash[ident].clear
125
+ hash[ident].push(*rval)
126
+ end
127
+ end
128
+ else
129
+ if array_spec
130
+ hash[ident] = []
131
+ set(hash)
132
+ else
133
+ if rval.is_a?(Array) and rval.size == 1
134
+ hash[ident] = rval.first
135
+ else
136
+ hash[ident] = rval
137
+ end
138
+ end
139
+ end
140
+ end
141
+ def inspect
142
+ if array_spec
143
+ return "#{ident}(#{array_spec.inspect}) = #{rval.inspect}"
144
+ else
145
+ return "#{ident} = #{rval}"
146
+ end
147
+ end
148
+ end
149
+
150
+ end
151
+
@@ -0,0 +1,470 @@
1
+ #
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by Racc 1.4.6
4
+ # from Racc grammer file "".
5
+ #
6
+
7
+ require 'racc/parser.rb'
8
+
9
+
10
+ require "strscan"
11
+ require "stringio"
12
+
13
+ class FortranNamelistScanner
14
+
15
+ def initialize (text)
16
+ @s = StringScanner.new(text)
17
+ @in_namelist = false
18
+ end
19
+
20
+ attr_accessor :in_namelist
21
+
22
+ def yylex
23
+ while @s.rest?
24
+ unless @in_namelist
25
+ case
26
+ when @s.scan(/\A([\$&])/) ### {$|&}
27
+ @in_namelist = true
28
+ return [
29
+ @s[0],
30
+ nil
31
+ ]
32
+ when @s.scan(/\A[^\$&]/)
33
+ next
34
+ end
35
+ else
36
+ case
37
+ when @s.scan(/\A[+-]?(\d+)\.(\d+)?([ED][+-]?(\d+))?/i) ### float
38
+ return [ ### 1.2E+3, 1.E+3, 1.2E3
39
+ :FLOAT, ### 1.2, 1.
40
+ @s[0].sub(/D/i,'e').sub(/\.e/,".0e").to_f
41
+ ]
42
+ when @s.scan(/\A[+-]?\.(\d+)([ED][+-]?(\d+))?/i) ### float
43
+ return [ ### .2E+3, -.2E+3, .2E3
44
+ :FLOAT, ### .2, -.2
45
+ @s[0].sub(/D/i,'e').sub(/\./, '0.').to_f
46
+ ]
47
+ when @s.scan(/\A[+-]?(\d+)[ED][+-]?(\d+)/i) ### float
48
+ return [ ### 12E+3, 12E3, 0E0
49
+ :FLOAT,
50
+ @s[0].sub(/D/i,'e').to_f
51
+ ]
52
+ when @s.scan(/\A[\-\+]?\d+/) ### digits
53
+ return [
54
+ :DIGITS,
55
+ Integer(@s[0])
56
+ ]
57
+ when @s.scan(/\A'((?:''|[^'])*)'/) ### 'quoted string'
58
+ return [
59
+ :STRING,
60
+ @s[1].gsub(/''/, "'")
61
+ ]
62
+ when @s.scan(/\A"((?:""|[^"])*)"/) ### 'double-quoted string'
63
+ return [
64
+ :STRING,
65
+ @s[1].gsub(/""/, '"')
66
+ ]
67
+ when @s.scan(/\A,/) ### ,
68
+ @s.scan(/\A\s+/)
69
+ while @s.scan(/\A\n\s*/) or @s.scan(/\A\![^\n]*/)
70
+ ### skip comment
71
+ end
72
+ if @s.match?(/\A[a-z]\w*/i) or @s.match?(/\A[\&\$\/\!]/)
73
+ return [
74
+ :COMMA,
75
+ nil
76
+ ]
77
+ elsif @s.match?(/\A,/)
78
+ return [
79
+ :NIL,
80
+ nil
81
+ ]
82
+ else
83
+ return [
84
+ ',',
85
+ nil
86
+ ]
87
+ end
88
+ when @s.scan(/\A[\$&\/=\(\):*]/) ### {$|&|/|,|=|(|)|:|*}
89
+ return [
90
+ @s[0],
91
+ nil
92
+ ]
93
+ when @s.scan(/\A[a-z]\w*/i) ### IDENT
94
+ return [
95
+ :IDENT,
96
+ @s[0]
97
+ ]
98
+ when @s.scan(/\A\s+/) ### blank
99
+ next
100
+ when @s.scan(/\A![^\n]*?\n/) ### comment
101
+ next
102
+ when @s.scan(/\A\n/) ### newline
103
+ next
104
+ else
105
+ @s.rest =~ /\A(.*)$/
106
+ raise "FortranFormat parse error\n\t#{$1}\n\t^"
107
+ end
108
+ end
109
+ end
110
+ end
111
+
112
+ end
113
+
114
+ class FortranNamelistParser < Racc::Parser
115
+
116
+ module_eval(<<'...end fortran_namelist.y/module_eval...', 'fortran_namelist.y', 94)
117
+
118
+ def parse (str)
119
+ @scan = FortranNamelistScanner.new(str)
120
+ @root = {}
121
+ do_parse
122
+ return @root
123
+ end
124
+
125
+ def next_token
126
+ return @scan.yylex
127
+ end
128
+
129
+ ...end fortran_namelist.y/module_eval...
130
+ ##### State transition tables begin ###
131
+
132
+ racc_action_table = [
133
+ 38, 28, 41, 36, 24, 25, 11, 22, 36, 24,
134
+ 25, 35, 22, 39, 24, 25, 35, 22, 28, 24,
135
+ 25, 1, 32, 2, 22, 18, 24, 25, 19, 11,
136
+ 20, 21, 14, 22, 29, 24, 25, 15, 1, 34,
137
+ 2, 13, 11, 40, 8, 7, 29, 45, 46, 47,
138
+ 6, 29, 33 ]
139
+
140
+ racc_action_check = [
141
+ 29, 46, 34, 48, 34, 34, 18, 46, 23, 46,
142
+ 46, 48, 48, 29, 48, 48, 23, 23, 14, 23,
143
+ 23, 4, 19, 4, 14, 12, 14, 14, 12, 12,
144
+ 12, 12, 11, 36, 15, 36, 36, 11, 0, 22,
145
+ 0, 8, 5, 30, 3, 2, 38, 39, 40, 45,
146
+ 1, 47, 20 ]
147
+
148
+ racc_action_pointer = [
149
+ 33, 44, 39, 44, 16, 36, nil, nil, 41, nil,
150
+ nil, 28, 23, nil, 12, 22, nil, nil, 0, 16,
151
+ 46, nil, 26, 5, nil, nil, nil, nil, nil, -3,
152
+ 33, nil, nil, nil, -10, nil, 21, nil, 34, 35,
153
+ 44, nil, nil, nil, nil, 46, -5, 39, 0, nil ]
154
+
155
+ racc_action_default = [
156
+ -31, -31, -31, -31, -1, -31, -4, -5, -31, -2,
157
+ -11, -31, -31, 50, -31, -31, -3, -12, -14, -7,
158
+ -6, -8, -25, -15, -24, -26, -17, -22, -21, -27,
159
+ -31, -13, -9, -10, -31, -19, -31, -18, -31, -31,
160
+ -31, -25, -23, -20, -29, -28, -31, -31, -16, -30 ]
161
+
162
+ racc_goto_table = [
163
+ 23, 30, 37, 10, 3, 16, 12, 42, 9, nil,
164
+ 17, nil, nil, nil, nil, 43, 31, nil, nil, nil,
165
+ nil, nil, nil, nil, 44, nil, nil, 37, nil, nil,
166
+ nil, nil, 48, 49 ]
167
+
168
+ racc_goto_check = [
169
+ 7, 8, 9, 6, 1, 5, 4, 10, 1, nil,
170
+ 6, nil, nil, nil, nil, 9, 6, nil, nil, nil,
171
+ nil, nil, nil, nil, 8, nil, nil, 9, nil, nil,
172
+ nil, nil, 7, 8 ]
173
+
174
+ racc_goto_pointer = [
175
+ nil, 4, nil, nil, 1, -7, -2, -14, -14, -21,
176
+ -27 ]
177
+
178
+ racc_goto_default = [
179
+ nil, nil, 4, 5, nil, nil, nil, nil, nil, 26,
180
+ 27 ]
181
+
182
+ racc_reduce_table = [
183
+ 0, 0, :racc_error,
184
+ 1, 18, :_reduce_none,
185
+ 2, 18, :_reduce_none,
186
+ 3, 19, :_reduce_3,
187
+ 2, 20, :_reduce_4,
188
+ 2, 20, :_reduce_5,
189
+ 1, 22, :_reduce_none,
190
+ 1, 22, :_reduce_none,
191
+ 1, 22, :_reduce_none,
192
+ 2, 22, :_reduce_9,
193
+ 2, 22, :_reduce_10,
194
+ 1, 21, :_reduce_11,
195
+ 2, 21, :_reduce_12,
196
+ 3, 21, :_reduce_13,
197
+ 2, 21, :_reduce_14,
198
+ 3, 23, :_reduce_15,
199
+ 6, 23, :_reduce_16,
200
+ 1, 24, :_reduce_17,
201
+ 2, 24, :_reduce_18,
202
+ 2, 24, :_reduce_19,
203
+ 3, 24, :_reduce_20,
204
+ 1, 24, :_reduce_21,
205
+ 1, 26, :_reduce_22,
206
+ 3, 26, :_reduce_23,
207
+ 1, 27, :_reduce_none,
208
+ 1, 27, :_reduce_none,
209
+ 1, 27, :_reduce_none,
210
+ 1, 25, :_reduce_27,
211
+ 3, 25, :_reduce_28,
212
+ 3, 25, :_reduce_29,
213
+ 5, 25, :_reduce_30 ]
214
+
215
+ racc_reduce_n = 31
216
+
217
+ racc_shift_n = 50
218
+
219
+ racc_token_table = {
220
+ false => 0,
221
+ :error => 1,
222
+ :COMMA => 2,
223
+ "," => 3,
224
+ "=" => 4,
225
+ "&" => 5,
226
+ :IDENT => 6,
227
+ "$" => 7,
228
+ "/" => 8,
229
+ "(" => 9,
230
+ ")" => 10,
231
+ :NIL => 11,
232
+ :DIGITS => 12,
233
+ "*" => 13,
234
+ :STRING => 14,
235
+ :FLOAT => 15,
236
+ ":" => 16 }
237
+
238
+ racc_nt_base = 17
239
+
240
+ racc_use_result_var = true
241
+
242
+ Racc_arg = [
243
+ racc_action_table,
244
+ racc_action_check,
245
+ racc_action_default,
246
+ racc_action_pointer,
247
+ racc_goto_table,
248
+ racc_goto_check,
249
+ racc_goto_default,
250
+ racc_goto_pointer,
251
+ racc_nt_base,
252
+ racc_reduce_table,
253
+ racc_token_table,
254
+ racc_shift_n,
255
+ racc_reduce_n,
256
+ racc_use_result_var ]
257
+
258
+ Racc_token_to_s_table = [
259
+ "$end",
260
+ "error",
261
+ "COMMA",
262
+ "\",\"",
263
+ "\"=\"",
264
+ "\"&\"",
265
+ "IDENT",
266
+ "\"$\"",
267
+ "\"/\"",
268
+ "\"(\"",
269
+ "\")\"",
270
+ "NIL",
271
+ "DIGITS",
272
+ "\"*\"",
273
+ "STRING",
274
+ "FLOAT",
275
+ "\":\"",
276
+ "$start",
277
+ "namelist_all",
278
+ "namelist",
279
+ "header",
280
+ "paramlist",
281
+ "tailer",
282
+ "paramdef",
283
+ "rvalues",
284
+ "array_spec",
285
+ "abbreb",
286
+ "constant" ]
287
+
288
+ Racc_debug_parser = false
289
+
290
+ ##### State transition tables end #####
291
+
292
+ # reduce 0 omitted
293
+
294
+ # reduce 1 omitted
295
+
296
+ # reduce 2 omitted
297
+
298
+ module_eval(<<'.,.,', 'fortran_namelist.y', 32)
299
+ def _reduce_3(val, _values, result)
300
+ @root[val[0]] = val[1]; @scan.in_namelist = false
301
+ result
302
+ end
303
+ .,.,
304
+
305
+ module_eval(<<'.,.,', 'fortran_namelist.y', 35)
306
+ def _reduce_4(val, _values, result)
307
+ result = val[1].downcase
308
+ result
309
+ end
310
+ .,.,
311
+
312
+ module_eval(<<'.,.,', 'fortran_namelist.y', 36)
313
+ def _reduce_5(val, _values, result)
314
+ result = val[1].downcase
315
+ result
316
+ end
317
+ .,.,
318
+
319
+ # reduce 6 omitted
320
+
321
+ # reduce 7 omitted
322
+
323
+ # reduce 8 omitted
324
+
325
+ module_eval(<<'.,.,', 'fortran_namelist.y', 42)
326
+ def _reduce_9(val, _values, result)
327
+ on_error unless val[1] =~ /\Aend\Z/i
328
+ result
329
+ end
330
+ .,.,
331
+
332
+ module_eval(<<'.,.,', 'fortran_namelist.y', 43)
333
+ def _reduce_10(val, _values, result)
334
+ on_error unless val[1] =~ /\Aend\Z/i
335
+ result
336
+ end
337
+ .,.,
338
+
339
+ module_eval(<<'.,.,', 'fortran_namelist.y', 46)
340
+ def _reduce_11(val, _values, result)
341
+ result = [val[0]]
342
+ result
343
+ end
344
+ .,.,
345
+
346
+ module_eval(<<'.,.,', 'fortran_namelist.y', 48)
347
+ def _reduce_12(val, _values, result)
348
+ result = val[0] + [val[1]]
349
+ result
350
+ end
351
+ .,.,
352
+
353
+ module_eval(<<'.,.,', 'fortran_namelist.y', 50)
354
+ def _reduce_13(val, _values, result)
355
+ result = val[0] + [val[2]]
356
+ result
357
+ end
358
+ .,.,
359
+
360
+ module_eval(<<'.,.,', 'fortran_namelist.y', 52)
361
+ def _reduce_14(val, _values, result)
362
+ result = val[0]
363
+ result
364
+ end
365
+ .,.,
366
+
367
+ module_eval(<<'.,.,', 'fortran_namelist.y', 56)
368
+ def _reduce_15(val, _values, result)
369
+ result = ParamDef.new(val[0].downcase.intern, nil, val[2])
370
+ result
371
+ end
372
+ .,.,
373
+
374
+ module_eval(<<'.,.,', 'fortran_namelist.y', 58)
375
+ def _reduce_16(val, _values, result)
376
+ result = ParamDef.new(val[0].downcase.intern, val[2], val[5])
377
+ result
378
+ end
379
+ .,.,
380
+
381
+ module_eval(<<'.,.,', 'fortran_namelist.y', 61)
382
+ def _reduce_17(val, _values, result)
383
+ result = val[0]
384
+ result
385
+ end
386
+ .,.,
387
+
388
+ module_eval(<<'.,.,', 'fortran_namelist.y', 63)
389
+ def _reduce_18(val, _values, result)
390
+ result = val[0] + val[1]
391
+ result
392
+ end
393
+ .,.,
394
+
395
+ module_eval(<<'.,.,', 'fortran_namelist.y', 65)
396
+ def _reduce_19(val, _values, result)
397
+ result = val[0] + [nil]
398
+ result
399
+ end
400
+ .,.,
401
+
402
+ module_eval(<<'.,.,', 'fortran_namelist.y', 67)
403
+ def _reduce_20(val, _values, result)
404
+ result = val[0] + val[2]
405
+ result
406
+ end
407
+ .,.,
408
+
409
+ module_eval(<<'.,.,', 'fortran_namelist.y', 69)
410
+ def _reduce_21(val, _values, result)
411
+ result = val[0]
412
+ result
413
+ end
414
+ .,.,
415
+
416
+ module_eval(<<'.,.,', 'fortran_namelist.y', 72)
417
+ def _reduce_22(val, _values, result)
418
+ result = [val[0]]
419
+ result
420
+ end
421
+ .,.,
422
+
423
+ module_eval(<<'.,.,', 'fortran_namelist.y', 74)
424
+ def _reduce_23(val, _values, result)
425
+ result = [val[2]] * val[0]
426
+ result
427
+ end
428
+ .,.,
429
+
430
+ # reduce 24 omitted
431
+
432
+ # reduce 25 omitted
433
+
434
+ # reduce 26 omitted
435
+
436
+ module_eval(<<'.,.,', 'fortran_namelist.y', 82)
437
+ def _reduce_27(val, _values, result)
438
+ result = [val[0]-1]
439
+ result
440
+ end
441
+ .,.,
442
+
443
+ module_eval(<<'.,.,', 'fortran_namelist.y', 84)
444
+ def _reduce_28(val, _values, result)
445
+ result = [(val[0]-1)..(val[2]-1)]
446
+ result
447
+ end
448
+ .,.,
449
+
450
+ module_eval(<<'.,.,', 'fortran_namelist.y', 86)
451
+ def _reduce_29(val, _values, result)
452
+ result = [val[0]-1] + val[2]
453
+ result
454
+ end
455
+ .,.,
456
+
457
+ module_eval(<<'.,.,', 'fortran_namelist.y', 88)
458
+ def _reduce_30(val, _values, result)
459
+ result = [(val[0]-1)..(val[2]-1)] + val[4]
460
+ result
461
+ end
462
+ .,.,
463
+
464
+ def _reduce_none(val, _values, result)
465
+ val[0]
466
+ end
467
+
468
+ end # class FortranNamelistParser
469
+
470
+