fortio-namelist 1.3.0 → 1.4.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: d6be9628b6a286eac9e31901c71c0793928166b260040cbe93d2d902a8c93096
4
- data.tar.gz: 80b6989bed8bb98e11ffae89a42fd6675f24454e7438287166915fb1fd56a0fc
3
+ metadata.gz: aa95f21c798ef2256d484af31914c2688bd6b210f2a0704b69b13646eb16b338
4
+ data.tar.gz: 18f9dac9edbe377bc934985b703b34793737476d143c9787852b84564ca011b4
5
5
  SHA512:
6
- metadata.gz: 3584a0f098e8f5ab224e02e01e60581483643034e25d326dcc04b5352c4ac1fdf1a83700cef61b012ba31b9822b1523707027c6aeb764789463a3465dd360eef
7
- data.tar.gz: 37328c227c9aa6e927111056a98ca92a4651a3740944319f166c62d6e1a60cea194fcbf04de30d0f63d0b5136dfdcf3024c7ca2eb5aec353880b58d5dd64ef02
6
+ metadata.gz: a841ab206370ee553dd92850da27009ed9dbd97ce43545843e5ff190afc5ae46407d30440f7f900708088de95c01598b4b0550c17a48b5b69a4ce205fc0fca14
7
+ data.tar.gz: f9f6da26c88005cd5c49ad8bb6a916d0731e98c0fd34f6f360d7760cb1fc9727209c4b313d33d4c3adfafbee2bcc8bf09c849dcbdb3a1901c2118e540d3e99d8
data/README.md CHANGED
@@ -1,15 +1,16 @@
1
-
2
1
  fortio-namelist
3
2
  ===============
4
3
 
5
- This is a library for reading and writing data in Fortran's namelist format. With this library, you can read Fortran's namelist format data from Ruby and convert it to Hash objects, and vice versa.
4
+ This is a Ruby library for reading and writing Fortran's namelist.
5
+ This library allows you to read a namelist string as a Hash object,
6
+ or dump a Hash object to a namelist string.
6
7
 
7
8
  Features
8
9
  --------
9
10
 
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)
11
+ * Flexible parsing of (too free) namelist format using Racc
12
+ * Reading namelist string as a Ruby's Hash object
13
+ * Converting a Hash object to a namelist string (specifying the format)
13
14
 
14
15
  Installation
15
16
  ------------
@@ -27,22 +28,22 @@ Usage
27
28
 
28
29
  ### Useful methods
29
30
 
30
- The user only needs to remember the following two methods.
31
+ To read and write a namelist, it is sufficient to use only the following two methods.
31
32
 
32
33
  FortIO::Namelist.parse(input, group: nil)
33
34
  FortIO::Namelist.dump(root, **format_options)
34
35
 
35
- ### Reading namelist string
36
+ ### Reading namelist
36
37
 
37
38
  To create a Hash object with namelist structure by reading a namelist string, use the following method.
38
39
 
39
40
  FortIO::Namelist.parse(input, group: nil)
40
41
 
41
- The argument `input` is given as a string, but it also accepts objects with a method `#read` returns a string like an IO object ('duck typing').
42
+ The argument `input` is given as a string, but it also accepts objects with a method `#read` which returns a string like an IO object ('duck typing').
42
43
 
43
- If the keyword argument `group` is omitted, all namelist groups included in `input` will be read. To read only a specific group, give a group name to `group`. To load multiple groups, give an array of group names to `group`.
44
+ To read only a specific group, give a group name to the keyword argument `group`. If `group` is omitted, all namelist groups included in `input` will be read. To load multiple groups, give an array of group names to `group`.
44
45
 
45
- Use lowercase Symbol objects for both group and variable names. The Hash object of the return value has a two-level structure as follows.
46
+ The Hash object of the return value has a two-level structure as follows.
46
47
 
47
48
  {
48
49
  group1: {
@@ -59,7 +60,7 @@ Use lowercase Symbol objects for both group and variable names. The Hash object
59
60
  :
60
61
  }
61
62
 
62
- The value can be Ruby's String, Integer, Float, Complex, TrueClass, or FalseClass objects, depending on the literal in the namelist. In the case that the value is an array, it will be expressed as an Array in Ruby.
63
+ The group and variable names are converted to lowercase Symbol objects and stored as keys in the hash. The value can be Ruby's String, Integer, Float, Complex, TrueClass, or FalseClass objects, depending on the literal in the namelist. In the case that the value is an array, it will be expressed as an Array in Ruby. We chose symbol as the key of the hash object because it is thought to be compatible with the pattern matching introduced in Ruby 2.7.
63
64
 
64
65
  Example:
65
66
 
@@ -82,17 +83,17 @@ input = %{
82
83
  }
83
84
 
84
85
  ### read all groups
85
- root = FortIO::Namelist.read(input)
86
+ root = FortIO::Namelist.parse(input)
86
87
  # => {:group1=>{:var1=>11, :var2=>12},
87
88
  # :group2=>{:var1=>12, :var2=>22},
88
89
  # :group3=>{:var1=>31, :var2=>32}}
89
90
 
90
91
  ### read only "group2"
91
- root = FortIO::Namelist.read(input, group: "group2")
92
+ root = FortIO::Namelist.parse(input, group: "group2")
92
93
  # => {:group2=>{:var1=>12, :var2=>22}}
93
94
 
94
95
  ### read only "group1" and "group3"
95
- root = FortIO::Namelist.read(input, group: ["group1", "group3"])
96
+ root = FortIO::Namelist.parse(input, group: ["group1", "group3"])
96
97
  # => {:group1=>{:var1=>11, :var2=>12},
97
98
  # :group3=>{:var1=>31, :var2=>32}}
98
99
 
@@ -137,7 +138,17 @@ This script print a namelist format string to stdout.
137
138
 
138
139
  You can finely control the output namelist string with the following keyword arguments (the first one is the default).
139
140
 
140
- #### `array_style` : Specifying the notation for array elements
141
+ * `array_style` : the notation for array elements
142
+ * `logical_format` : boolean literals
143
+ * `float_format` : the notation for floating point numbers
144
+ * `alignment` : how variable identifiers are aligned
145
+ * `uppercase` : whether variable names, etc. should be uppercase or lowercase.
146
+ * `separator` : the separator between variable definitions
147
+ * `group_end` : the group terminator
148
+ * `indent` : the indentation for variable definition
149
+
150
+
151
+ #### `array_style` specifies the notation for array elements
141
152
 
142
153
  * 'stream' : (default)
143
154
  * 'index' :
@@ -166,7 +177,7 @@ puts FortIO::Namelist.dump(root, array_style: 'index')
166
177
  # /
167
178
  ```
168
179
 
169
- #### `logical_format` : Specifying a boolean literal
180
+ #### `logical_format` specifies boolean literals
170
181
 
171
182
  * 'normal' : normal notation like `.true.`, `.false` (default)
172
183
  * 'short' : short notation like `t`, `f`
@@ -189,7 +200,7 @@ puts FortIO::Namelist.dump(root, logical_format: 'short')
189
200
  # /
190
201
  ```
191
202
 
192
- #### `float_format` : Specifying notation for floating point numbers
203
+ #### `float_format` specifies the notation for floating point numbers
193
204
 
194
205
  * 'normal' : format with "%g" (default)
195
206
  * 'd0' : format with "%g" followed by 'd0'
@@ -223,7 +234,7 @@ puts FortIO::Namelist.dump(root, float_format: 'exp')
223
234
  # /
224
235
  ```
225
236
 
226
- #### `alignment` : Specifying how variable identifiers are aligned
237
+ #### `alignment` specifies how variable identifiers are aligned
227
238
 
228
239
  * 'left' : aligned, left-justified, position of '=' can be specified by number eg. 'left:7' (default)
229
240
  * 'right' : aligned, right-justified, position of '=' can be specified by number eg. 'right:7'
@@ -280,7 +291,7 @@ puts FortIO::Namelist.dump(root, alignment: 'stream')
280
291
  # /
281
292
  ```
282
293
 
283
- #### `uppercase` : Specify whether variable names, etc. should be uppercase or lowercase.
294
+ #### `uppercase` specifies whether variable names, etc. should be uppercase or lowercase.
284
295
 
285
296
  * false : (default)
286
297
  * true :
@@ -303,7 +314,7 @@ puts FortIO::Namelist.dump(root, uppercase: true)
303
314
  # /
304
315
  ```
305
316
 
306
- #### `separator` : Specifying the separator between variable definitions
317
+ #### `separator` specifies the separator between variable definitions
307
318
 
308
319
  * "comma", "," : comma + NL separeted (default)
309
320
  * "nl", "\n" : NL separated
@@ -339,7 +350,7 @@ puts FortIO::Namelist.dump(root, separator: "nl")
339
350
  # /
340
351
  ```
341
352
 
342
- #### `group_end` : Specifying a group terminator
353
+ #### `group_end` specifies the group terminator
343
354
 
344
355
  * "slash", "/" : end with `/` (default)
345
356
  * "end" : end with `&end`
@@ -362,7 +373,7 @@ puts FortIO::Namelist.dump(root, group_end: 'end')
362
373
  # &end
363
374
  ```
364
375
 
365
- #### `indent` : Specifying the indentation for variable definition
376
+ #### `indent` specifies the indentation for variable definition
366
377
 
367
378
  * ' '*2 : two spaces (default)
368
379
 
@@ -1,5 +1,5 @@
1
1
  Gem::Specification::new do |s|
2
- version = "1.3.0"
2
+ version = "1.4.0"
3
3
  files = Dir.glob("**/*") - [
4
4
  Dir.glob("fortio-namelist-*.gem"),
5
5
  Dir.glob("test/**/*"),
@@ -10,10 +10,12 @@ Gem::Specification::new do |s|
10
10
  s.name = "fortio-namelist"
11
11
  s.summary = "A library for reading/writing fortran namelist file"
12
12
  s.description = <<-HERE
13
- A library for reading/writing fortran namelist file
13
+ This is a Ruby library for reading and writing Fortran's namelist.
14
+ This library allows you to read a namelist string as a Hash object,
15
+ or dump a Hash object to a namelist string.
14
16
  HERE
15
17
  s.version = version
16
- s.licenses = ['MIT']
18
+ s.license = 'MIT'
17
19
  s.author = "Hiroki Motoyoshi"
18
20
  s.email = ""
19
21
  s.homepage = 'https://github.com/himotoyoshi/fortio-namelist'
@@ -98,14 +98,7 @@ module FortIO::Namelist
98
98
  #
99
99
 
100
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
101
+ return value.to_s.sub(/e/, d)
109
102
  end
110
103
 
111
104
  def self.format_element (value,
data/spec/dump_spec.rb CHANGED
@@ -11,7 +11,7 @@ describe "FortIO::Namelist" do
11
11
  &example
12
12
  v1 = 1.234567890123456,
13
13
  v2 = 0.123456789012345,
14
- v3 = 1.234567890123456d+10
14
+ v3 = 12345678901.23456
15
15
  /
16
16
  HERE
17
17
 
@@ -26,7 +26,7 @@ HERE
26
26
  &example
27
27
  v1 = 1.234567890123456d0,
28
28
  v2 = 0.123456789012345d0,
29
- v3 = 1.234567890123456d+10
29
+ v3 = 12345678901.23456d0
30
30
  /
31
31
  HERE
32
32
 
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.3.0
4
+ version: 1.4.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-04-02 00:00:00.000000000 Z
11
+ date: 2021-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: racc
@@ -24,7 +24,9 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
- description: " A library for reading/writing fortran namelist file\n"
27
+ description: " This is a Ruby library for reading and writing Fortran's namelist.
28
+ \n This library allows you to read a namelist string as a Hash object, \n or dump
29
+ a Hash object to a namelist string.\n"
28
30
  email: ''
29
31
  executables: []
30
32
  extensions: []