fortio-namelist 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7031390445d9ff81165021b8e46fd90057b89748b6cfb7a2989cc645baeda333
4
- data.tar.gz: e4f9bbbcc74241ba959796683606f06903ec94710350a7a2ec466532eb0ed2b8
3
+ metadata.gz: d6be9628b6a286eac9e31901c71c0793928166b260040cbe93d2d902a8c93096
4
+ data.tar.gz: 80b6989bed8bb98e11ffae89a42fd6675f24454e7438287166915fb1fd56a0fc
5
5
  SHA512:
6
- metadata.gz: cf26eaf52e837df1eaa2385971129b086a9939cf370c0b6ee77f63717239792763c2d15a4594e0dcf4b5e45399fd3e50630ec8b362966c3068d538a712f14a9b
7
- data.tar.gz: 0d5217634f78f0963b8eafb2638d584c680fa2746336fff36e5039196f84bab4f74462b81b4e34eea0b87c4dcf184a9069c56972de85744ea342906bc9d7601f
6
+ metadata.gz: 3584a0f098e8f5ab224e02e01e60581483643034e25d326dcc04b5352c4ac1fdf1a83700cef61b012ba31b9822b1523707027c6aeb764789463a3465dd360eef
7
+ data.tar.gz: 37328c227c9aa6e927111056a98ca92a4651a3740944319f166c62d6e1a60cea194fcbf04de30d0f63d0b5136dfdcf3024c7ca2eb5aec353880b58d5dd64ef02
data/README.md CHANGED
@@ -7,9 +7,9 @@ This is a library for reading and writing data in Fortran's namelist format. Wit
7
7
  Features
8
8
  --------
9
9
 
10
- * Flexible parsing enables reading of namelists in various formats.
11
- * Various options to control the output namelist string in the format of your choice.
12
- * Able to convert namelist format to JSON or YAML format using Ruby's standard library
10
+ * Flexible parsing using Racc to support various dialects
11
+ * Options for controlling the format of the dump
12
+ * Represents the structure of a name list with a Hash object (easy to convert to JSON or YAML format)
13
13
 
14
14
  Installation
15
15
  ------------
@@ -27,14 +27,14 @@ Usage
27
27
 
28
28
  ### Useful methods
29
29
 
30
- It is enough for the user to remember the following two methods.
30
+ The user only needs to remember the following two methods.
31
31
 
32
32
  FortIO::Namelist.parse(input, group: nil)
33
33
  FortIO::Namelist.dump(root, **format_options)
34
34
 
35
- ### Reading namelist format string
35
+ ### Reading namelist string
36
36
 
37
- To create a Hash object with namelist structure by reading a string in namelist format, use the following method.
37
+ To create a Hash object with namelist structure by reading a namelist string, use the following method.
38
38
 
39
39
  FortIO::Namelist.parse(input, group: nil)
40
40
 
@@ -83,55 +83,28 @@ input = %{
83
83
 
84
84
  ### read all groups
85
85
  root = FortIO::Namelist.read(input)
86
- => {:group1=>{:var1=>11, :var2=>12},
87
- :group2=>{:var1=>12, :var2=>22},
88
- :group3=>{:var1=>31, :var2=>32}}
89
-
86
+ # => {:group1=>{:var1=>11, :var2=>12},
87
+ # :group2=>{:var1=>12, :var2=>22},
88
+ # :group3=>{:var1=>31, :var2=>32}}
90
89
 
91
90
  ### read only "group2"
92
91
  root = FortIO::Namelist.read(input, group: "group2")
93
- => {:group2=>{:var1=>12, :var2=>22}}
94
-
92
+ # => {:group2=>{:var1=>12, :var2=>22}}
95
93
 
96
94
  ### read only "group1" and "group3"
97
95
  root = FortIO::Namelist.read(input, group: ["group1", "group3"])
98
- => {:group1=>{:var1=>11, :var2=>12},
99
- :group3=>{:var1=>31, :var2=>32}}
96
+ # => {:group1=>{:var1=>11, :var2=>12},
97
+ # :group3=>{:var1=>31, :var2=>32}}
100
98
 
101
99
  ```
102
100
 
103
- ### Generating namelist format string from Hash object with namelist structure
101
+ ### Generating namelist string from Hash object with namelist structure
104
102
 
105
- To generate a namelist format string from a Hash object with a namelist structure, use the following method.
103
+ To generate a namelist string from a Hash object with a namelist structure, use the following method.
106
104
 
107
105
  FortIO::Namelist.dump(root, **format_options)
108
106
 
109
- The argument `root` is given as a Hash object. The return value is a string in namelist format. You can finely control the output namelist string with the following keyword arguments (the first one is the default).
110
-
111
- array_style: 'stream'
112
- 'index'
113
-
114
- logical_format: 'normal'
115
- 'short'
116
-
117
- float_format: 'normal'
118
- 'd0'
119
-
120
- alignment: 'left'
121
- 'right'
122
- 'compact'
123
- Integer
124
-
125
- uppercase: false
126
- true
127
-
128
- separator: "comma", ","
129
- "nl", "\n"
130
-
131
- group_end: "slash", "/"
132
- "end"
133
-
134
- indent: ' '*2
107
+ The argument `root` is given as a Hash object. The return value is a namelist string.
135
108
 
136
109
  Example:
137
110
 
@@ -159,3 +132,254 @@ This script print a namelist format string to stdout.
159
132
  var1 = 31,
160
133
  var2 = 32
161
134
  /
135
+
136
+ ### Format options for `FortIO::Namelist.dump`
137
+
138
+ You can finely control the output namelist string with the following keyword arguments (the first one is the default).
139
+
140
+ #### `array_style` : Specifying the notation for array elements
141
+
142
+ * 'stream' : (default)
143
+ * 'index' :
144
+
145
+ Example:
146
+
147
+ ```ruby
148
+ root = {group: {var1: [1,2,3], var2: ["a","b","c"]}}
149
+
150
+ puts FortIO::Namelist.dump(root, array_style: 'stream')
151
+ # =>
152
+ # &group
153
+ # var1 = 1, 2, 3,
154
+ # var2 = 'a', 'b', 'c'
155
+ # /
156
+
157
+ puts FortIO::Namelist.dump(root, array_style: 'index')
158
+ # =>
159
+ # &group
160
+ # var1(1) = 1,
161
+ # var1(2) = 2,
162
+ # var1(3) = 3,
163
+ # var2(1) = 'a',
164
+ # var2(2) = 'b',
165
+ # var2(3) = 'c'
166
+ # /
167
+ ```
168
+
169
+ #### `logical_format` : Specifying a boolean literal
170
+
171
+ * 'normal' : normal notation like `.true.`, `.false` (default)
172
+ * 'short' : short notation like `t`, `f`
173
+
174
+ ```ruby
175
+ root = {group: {var1: true, var2: false}}
176
+
177
+ puts FortIO::Namelist.dump(root, logical_format: 'normal')
178
+ # =>
179
+ # &group
180
+ # var1 = .true.,
181
+ # var2 = .false.
182
+ # /
183
+
184
+ puts FortIO::Namelist.dump(root, logical_format: 'short')
185
+ # =>
186
+ # &group
187
+ # var1 = t,
188
+ # var2 = f
189
+ # /
190
+ ```
191
+
192
+ #### `float_format` : Specifying notation for floating point numbers
193
+
194
+ * 'normal' : format with "%g" (default)
195
+ * 'd0' : format with "%g" followed by 'd0'
196
+ * 'exp' : exponential notation
197
+
198
+ ```ruby
199
+ root = {group: {var1: 1.0, var2: 12.75, var3: 50.0e-8}}
200
+
201
+ puts FortIO::Namelist.dump(root, float_format: 'normal')
202
+ # =>
203
+ # &group
204
+ # var1 = 1,
205
+ # var2 = 12.75,
206
+ # var3 = 5d-07
207
+ # /
208
+
209
+ puts FortIO::Namelist.dump(root, float_format: 'd0')
210
+ # =>
211
+ # &group
212
+ # var1 = 1d0,
213
+ # var2 = 12.75d0,
214
+ # var3 = 5d-07
215
+ # /
216
+
217
+ puts FortIO::Namelist.dump(root, float_format: 'exp')
218
+ # =>
219
+ # &group
220
+ # var1 = 1d+00,
221
+ # var2 = 1.275d+01,
222
+ # var3 = 5d-07
223
+ # /
224
+ ```
225
+
226
+ #### `alignment` : Specifying how variable identifiers are aligned
227
+
228
+ * 'left' : aligned, left-justified, position of '=' can be specified by number eg. 'left:7' (default)
229
+ * 'right' : aligned, right-justified, position of '=' can be specified by number eg. 'right:7'
230
+ * 'none' : not aligned
231
+ * 'stream' : not aligned, stream style, length of each line can be specified by number eg. 'stream:70'
232
+
233
+ ```ruby
234
+ root = {group: {var1: 1, variable2: [1,2,3], v3: true}}
235
+
236
+ puts FortIO::Namelist.dump(root, alignment: 'left')
237
+ # =>
238
+ # &group
239
+ # var1 = 1,
240
+ # variable2 = 1, 2, 3,
241
+ # v3 = .true.
242
+ # /
243
+
244
+ puts FortIO::Namelist.dump(root, alignment: 'left:7')
245
+ # =>
246
+ # &group
247
+ # var1 = 1,
248
+ # variable2 = 1, 2, 3,
249
+ # v3 = .true.
250
+ # /
251
+
252
+ puts FortIO::Namelist.dump(root, alignment: 'right')
253
+ # =>
254
+ # &group
255
+ # var1 = 1,
256
+ # variable2 = 1, 2, 3,
257
+ # v3 = .true.
258
+ # /
259
+
260
+ puts FortIO::Namelist.dump(root, alignment: 'right:7')
261
+ # =>
262
+ # &group
263
+ # var1 = 1,
264
+ # variable2 = 1, 2, 3,
265
+ # v3 = .true.
266
+ # /
267
+
268
+ puts FortIO::Namelist.dump(root, alignment: 'none')
269
+ # =>
270
+ # &group
271
+ # var1 = 1,
272
+ # variable2 = 1, 2, 3,
273
+ # v3 = .true.
274
+ # /
275
+
276
+ puts FortIO::Namelist.dump(root, alignment: 'stream')
277
+ # =>
278
+ # &group
279
+ # var1 = 1, variable2 = 1, 2, 3, v3 = .true.,
280
+ # /
281
+ ```
282
+
283
+ #### `uppercase` : Specify whether variable names, etc. should be uppercase or lowercase.
284
+
285
+ * false : (default)
286
+ * true :
287
+
288
+ ```ruby
289
+ root = {group: {var1: 1, var2: "a"}}
290
+
291
+ puts FortIO::Namelist.dump(root, uppercase: false)
292
+ # =>
293
+ # &group
294
+ # var1 = 1,
295
+ # val2 = 'a'
296
+ # /
297
+
298
+ puts FortIO::Namelist.dump(root, uppercase: true)
299
+ # =>
300
+ # &GROUP
301
+ # VAR1 = 1,
302
+ # VAL2 = 'a'
303
+ # /
304
+ ```
305
+
306
+ #### `separator` : Specifying the separator between variable definitions
307
+
308
+ * "comma", "," : comma + NL separeted (default)
309
+ * "nl", "\n" : NL separated
310
+
311
+ ```ruby
312
+ root = {group1: {var1: 1, var2: "a", var3: true},
313
+ group2: {var1: 2, var2: "b", var3: false}}
314
+
315
+ puts FortIO::Namelist.dump(root, separator: "comma")
316
+ # =>
317
+ # &group1
318
+ # var1 = 1,
319
+ # var2 = 'a',
320
+ # var3 = .true.
321
+ # /
322
+ # &group2
323
+ # var1 = 2,
324
+ # var2 = 'b',
325
+ # var3 = .false.
326
+ # /
327
+
328
+ puts FortIO::Namelist.dump(root, separator: "nl")
329
+ # =>
330
+ # &group1
331
+ # var1 = 1
332
+ # var2 = 'a'
333
+ # var3 = .true.
334
+ # /
335
+ # &group2
336
+ # var1 = 2
337
+ # var2 = 'b'
338
+ # var3 = .false.
339
+ # /
340
+ ```
341
+
342
+ #### `group_end` : Specifying a group terminator
343
+
344
+ * "slash", "/" : end with `/` (default)
345
+ * "end" : end with `&end`
346
+
347
+ ```ruby
348
+ root = {group: {var1: true, var2: false}}
349
+
350
+ puts FortIO::Namelist.dump(root, group_end: 'slash')
351
+ # =>
352
+ # &group
353
+ # var1 = .true.,
354
+ # var2 = .false.
355
+ # /
356
+
357
+ puts FortIO::Namelist.dump(root, group_end: 'end')
358
+ # =>
359
+ # &group
360
+ # var1 = .true.,
361
+ # var2 = .false.
362
+ # &end
363
+ ```
364
+
365
+ #### `indent` : Specifying the indentation for variable definition
366
+
367
+ * ' '*2 : two spaces (default)
368
+
369
+ ```ruby
370
+ root = {group: {var1: true, var2: false}}
371
+
372
+ puts FortIO::Namelist.dump(root, indent: ' '*2)
373
+ # =>
374
+ # &group
375
+ # var1 = .true.,
376
+ # var2 = .false.
377
+ # /
378
+
379
+ puts FortIO::Namelist.dump(root, indent: ' '*4)
380
+ # =>
381
+ # &group
382
+ # var1 = .true.,
383
+ # var2 = .false.
384
+ # /
385
+ ```
@@ -1,5 +1,5 @@
1
1
  Gem::Specification::new do |s|
2
- version = "1.2.1"
2
+ version = "1.3.0"
3
3
  files = Dir.glob("**/*") - [
4
4
  Dir.glob("fortio-namelist-*.gem"),
5
5
  Dir.glob("test/**/*"),
@@ -97,6 +97,17 @@ module FortIO::Namelist
97
97
  # hash -> namelist converter
98
98
  #
99
99
 
100
+ def self.float_to_string (value, d:)
101
+ if value == 0
102
+ return "0.0"
103
+ elsif Math.log10(value).between?(-4,4)
104
+ return "%.16g" % value
105
+ else
106
+ num,exp = ("%.16e" % value).split(/e/)
107
+ return ("%.16g" % num) + d + exp
108
+ end
109
+ end
110
+
100
111
  def self.format_element (value,
101
112
  logical_format: 'normal',
102
113
  float_format: 'normal',
@@ -112,12 +123,13 @@ module FortIO::Namelist
112
123
  d = uppercase ? "D" : "d"
113
124
  case float_format
114
125
  when 'normal'
115
- return ("%g" % value).sub(/e/, d)
126
+ float_to_string(value, d: d)
116
127
  when 'd0'
117
- value = ("%g" % value)
118
- return ( value =~ /e/ ) ? value.sub(/e/, d) : value + d + "0"
128
+ value = float_to_string(value, d: d)
129
+ return ( value =~ /#{d}/ ) ? value : value + d + "0"
119
130
  when 'exp'
120
- return ("%e" % value).sub(/e/, d)
131
+ num,exp = ("%.16e" % value).split(/e/)
132
+ return ("%.16g" % num) + d + exp
121
133
  else
122
134
  raise "invalid float_format"
123
135
  end
@@ -191,24 +203,47 @@ module FortIO::Namelist
191
203
  raise "invalid keyword argument `separator` (should be 'comma', ',', 'nl', '\n')"
192
204
  end
193
205
  case alignment
206
+ when /\Astream(:(\d+))?/
207
+ maxlen = $2 ? $2.to_i : 79 - indent.size
208
+ elements = list.map { |ident, value|
209
+ format("%s = %s", ident, value)
210
+ }
211
+ body = ""
212
+ line = []
213
+ len = indent.size
214
+ elements.each do |e|
215
+ if len + e.length >= maxlen
216
+ body += indent + line.join(", ") + nl
217
+ line = []
218
+ len = indent.size
219
+ end
220
+ line << e
221
+ len += e.length + 2
222
+ end
223
+ body += indent + line.join(", ") + nl unless line.empty?
224
+ body = body.chomp
194
225
  when "none"
195
226
  body = list.map { |ident, value|
196
227
  format("%s%s = %s", indent, ident, value)
197
228
  }.join(nl)
198
- when "left"
199
- ident_maxlen = list.map{|ident,value| ident.length}.max
229
+ when /\Aleft(:(\d+))?/
230
+ if $2
231
+ ident_maxlen = $2.to_i - indent.size
232
+ else
233
+ ident_maxlen = list.map{|ident,value| ident.length}.max
234
+ end
200
235
  body = list.map { |ident, value|
201
236
  format("%s%-#{ident_maxlen}s = %s", indent, ident, value)
202
237
  }.join(nl)
203
- when "right"
204
- ident_maxlen = list.map{|ident,value| ident.length}.max
238
+ when /\Aright(:(\d+))?/
239
+ if $2
240
+ ident_maxlen = $2.to_i - indent.size
241
+ else
242
+ ident_maxlen = list.map{|ident,value| ident.length}.max
243
+ end
205
244
  body = list.map { |ident, value|
206
245
  format("%s%#{ident_maxlen}s = %s", indent, ident, value)
207
246
  }.join(nl)
208
- when Integer
209
- body = list.map { |ident, value|
210
- format("%s%-#{alignment-2}s = %s", indent, ident, value)
211
- }.join(nl)
212
247
  else
213
248
  raise "invalid keyword argument `alignment` (should be 'normal' 'left' 'right' 'stream')"
214
249
  end
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # DO NOT MODIFY!!!!
3
- # This file is automatically generated by Racc 1.5.2
3
+ # This file is automatically generated by Racc 1.4.16
4
4
  # from Racc grammar file "".
5
5
  #
6
6
 
@@ -243,36 +243,36 @@ module_eval(<<'...end fortran_namelist.y/module_eval...', 'fortran_namelist.y',
243
243
  ##### State transition tables begin ###
244
244
 
245
245
  racc_action_table = [
246
- 48, 34, 65, 63, 47, 4, 5, 39, 14, 41,
247
- 62, 42, 43, 46, 49, 48, 66, 10, 13, 47,
248
- 15, 13, 39, 29, 41, 30, 42, 43, 46, 49,
249
- 47, 23, 24, 56, 55, 41, 47, 42, 43, 46,
250
- 13, 41, 47, 42, 43, 46, 26, 59, 24, 42,
251
- 43, 46, 4, 5, 21, 10, 13, 18, 4, 5,
252
- 21, 24, 59, 18, 13, 33, 46, 59, 30, 51,
253
- 7, 46, 4, 5, 13, 13, 57, 58, 61, 24,
254
- 24, 68, 70, 51, 74, 75, 51 ]
246
+ 65, 51, 63, 14, 48, 4, 5, 21, 47, 62,
247
+ 18, 39, 15, 41, 66, 42, 43, 46, 49, 48,
248
+ 34, 13, 13, 47, 26, 30, 39, 24, 41, 47,
249
+ 42, 43, 46, 49, 41, 51, 42, 43, 46, 47,
250
+ 4, 5, 56, 55, 41, 47, 42, 43, 46, 13,
251
+ 59, 13, 42, 43, 46, 4, 5, 21, 59, 13,
252
+ 18, 29, 46, 30, 59, 24, 23, 24, 46, 33,
253
+ 7, 57, 4, 5, 10, 13, 10, 13, 58, 61,
254
+ 24, 24, 68, 70, 51, 74, 75 ]
255
255
 
256
256
  racc_action_check = [
257
- 28, 28, 57, 51, 28, 0, 0, 28, 6, 28,
258
- 51, 28, 28, 28, 28, 69, 57, 3, 3, 69,
259
- 7, 21, 69, 21, 69, 21, 69, 69, 69, 69,
260
- 36, 11, 11, 36, 36, 36, 55, 36, 36, 36,
261
- 10, 55, 58, 55, 55, 55, 19, 58, 22, 58,
262
- 58, 58, 9, 9, 9, 16, 16, 9, 25, 25,
263
- 25, 27, 47, 25, 61, 27, 47, 68, 61, 29,
264
- 1, 68, 1, 1, 30, 33, 37, 41, 50, 52,
265
- 53, 60, 62, 63, 70, 72, 74 ]
257
+ 57, 74, 51, 6, 69, 25, 25, 25, 69, 51,
258
+ 25, 69, 7, 69, 57, 69, 69, 69, 69, 28,
259
+ 28, 61, 10, 28, 19, 61, 28, 22, 28, 55,
260
+ 28, 28, 28, 28, 55, 29, 55, 55, 55, 36,
261
+ 0, 0, 36, 36, 36, 58, 36, 36, 36, 30,
262
+ 58, 33, 58, 58, 58, 9, 9, 9, 47, 21,
263
+ 9, 21, 47, 21, 68, 27, 11, 11, 68, 27,
264
+ 1, 37, 1, 1, 16, 16, 3, 3, 41, 50,
265
+ 52, 53, 60, 62, 63, 70, 72 ]
266
266
 
267
267
  racc_action_pointer = [
268
- 3, 70, nil, 12, nil, nil, 4, 20, nil, 50,
269
- 34, 26, nil, nil, nil, nil, 50, nil, nil, 42,
270
- nil, 15, 42, nil, nil, 56, nil, 55, -4, 56,
271
- 68, nil, nil, 69, nil, nil, 22, 64, nil, nil,
272
- nil, 63, nil, nil, nil, nil, nil, 49, nil, nil,
273
- 69, -9, 73, 74, nil, 28, nil, -2, 34, nil,
274
- 69, 58, 69, 70, nil, nil, nil, nil, 54, 11,
275
- 72, nil, 76, nil, 73, nil, nil ]
268
+ 38, 70, nil, 71, nil, nil, -1, 12, nil, 53,
269
+ 16, 61, nil, nil, nil, nil, 69, nil, nil, 20,
270
+ nil, 53, 21, nil, nil, 3, nil, 59, 15, 22,
271
+ 43, nil, nil, 45, nil, nil, 31, 59, nil, nil,
272
+ nil, 64, nil, nil, nil, nil, nil, 45, nil, nil,
273
+ 70, -10, 74, 75, nil, 21, nil, -4, 37, nil,
274
+ 70, 15, 70, 71, nil, nil, nil, nil, 51, 0,
275
+ 73, nil, 77, nil, -12, nil, nil ]
276
276
 
277
277
  racc_action_default = [
278
278
  -51, -51, -2, -15, -5, -6, -51, -51, -1, -51,
@@ -285,24 +285,24 @@ racc_action_default = [
285
285
  -48, -49, -51, -22, -51, -42, -50 ]
286
286
 
287
287
  racc_goto_table = [
288
- 22, 50, 35, 60, 28, 17, 54, 2, 8, 9,
289
- 19, 27, 20, 1, 16, 67, nil, nil, nil, nil,
290
- 52, 31, 25, 53, 72, 64, 19, nil, 32, nil,
288
+ 22, 50, 35, 60, 28, 20, 54, 2, 8, 9,
289
+ 17, 27, 19, 1, 16, 67, nil, nil, nil, nil,
290
+ 52, 32, 25, 53, 72, 64, 31, nil, 19, nil,
291
291
  nil, nil, nil, nil, nil, 71, nil, nil, nil, nil,
292
292
  nil, nil, nil, 73, 69, nil, 76, nil, nil, nil,
293
293
  nil, 27 ]
294
294
 
295
295
  racc_goto_check = [
296
- 8, 13, 12, 18, 11, 6, 16, 2, 2, 4,
297
- 7, 8, 10, 1, 5, 17, nil, nil, nil, nil,
298
- 8, 6, 4, 8, 18, 16, 7, nil, 10, nil,
296
+ 8, 13, 12, 18, 11, 10, 16, 2, 2, 4,
297
+ 6, 8, 7, 1, 5, 17, nil, nil, nil, nil,
298
+ 8, 10, 4, 8, 18, 16, 6, nil, 7, nil,
299
299
  nil, nil, nil, nil, nil, 13, nil, nil, nil, nil,
300
300
  nil, nil, nil, 12, 11, nil, 13, nil, nil, nil,
301
301
  nil, 8 ]
302
302
 
303
303
  racc_goto_pointer = [
304
- nil, 13, 7, nil, 6, 5, -4, 1, -10, nil,
305
- 3, -17, -26, -28, nil, nil, -30, -43, -44, nil ]
304
+ nil, 13, 7, nil, 6, 5, 1, 3, -10, nil,
305
+ -4, -17, -26, -28, nil, nil, -30, -43, -44, nil ]
306
306
 
307
307
  racc_goto_default = [
308
308
  nil, nil, nil, 3, nil, nil, nil, 6, 11, 12,
data/spec/dump_spec.rb ADDED
@@ -0,0 +1,51 @@
1
+ require "fortio-namelist"
2
+ require "rspec-power_assert"
3
+
4
+ describe "FortIO::Namelist" do
5
+
6
+ example "dumping float" do
7
+ root = {example: {v1: 1.234567890123456, v2: 0.123456789012345, v3: 1.234567890123456e10}}
8
+ output = FortIO::Namelist.dump(root)
9
+
10
+ answer = <<HERE
11
+ &example
12
+ v1 = 1.234567890123456,
13
+ v2 = 0.123456789012345,
14
+ v3 = 1.234567890123456d+10
15
+ /
16
+ HERE
17
+
18
+ is_asserted_by { output == answer }
19
+ end
20
+
21
+ example "dumping float 'd0'" do
22
+ root = {example: {v1: 1.234567890123456, v2: 0.123456789012345, v3: 1.234567890123456e10}}
23
+ output = FortIO::Namelist.dump(root, float_format: 'd0')
24
+
25
+ answer = <<HERE
26
+ &example
27
+ v1 = 1.234567890123456d0,
28
+ v2 = 0.123456789012345d0,
29
+ v3 = 1.234567890123456d+10
30
+ /
31
+ HERE
32
+
33
+ is_asserted_by { output == answer }
34
+ end
35
+
36
+ example "dumping float 'exp'" do
37
+ root = {example: {v1: 1.234567890123456, v2: 0.123456789012345, v3: 1.234567890123456e10}}
38
+ output = FortIO::Namelist.dump(root, float_format: 'exp')
39
+
40
+ answer = <<HERE
41
+ &example
42
+ v1 = 1.234567890123456d+00,
43
+ v2 = 1.23456789012345d-01,
44
+ v3 = 1.234567890123456d+10
45
+ /
46
+ HERE
47
+
48
+ is_asserted_by { output == answer }
49
+ end
50
+
51
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fortio-namelist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroki Motoyoshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-03 00:00:00.000000000 Z
11
+ date: 2021-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: racc
@@ -39,6 +39,7 @@ files:
39
39
  - lib/fortio-namelist/fortran_namelist.tab.rb
40
40
  - lib/fortio-namelist/fortran_namelist.y
41
41
  - spec/array_spec.rb
42
+ - spec/dump_spec.rb
42
43
  - spec/empty_spec.rb
43
44
  - spec/identifier_spec.rb
44
45
  - spec/scalar_spec.rb
@@ -62,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
63
  - !ruby/object:Gem::Version
63
64
  version: '0'
64
65
  requirements: []
65
- rubygems_version: 3.0.3
66
+ rubygems_version: 3.1.2
66
67
  signing_key:
67
68
  specification_version: 4
68
69
  summary: A library for reading/writing fortran namelist file