mdarray 0.5.3-java → 0.5.4-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +325 -70
- data/doc/20130625 MDArray Internals.docx +0 -0
- data/lib/colt/colt.rb +2 -0
- data/lib/colt/matrix/colt_matrix.rb +365 -0
- data/lib/colt/matrix/matrix2D_floating_algebra.rb +325 -0
- data/lib/colt/matrix/matrix_hierarchy.rb +258 -0
- data/lib/mdarray.rb +54 -3
- data/lib/mdarray/access.rb +16 -0
- data/lib/mdarray/counter.rb +16 -0
- data/lib/mdarray/creation.rb +13 -1
- data/lib/mdarray/lazy_mdarray.rb +6 -2
- data/lib/mdarray/lazy_operators.rb +8 -0
- data/lib/mdarray/printing.rb +18 -3
- data/lib/mdarray/section.rb +101 -0
- data/lib/netcdf/attribute.rb +154 -0
- data/lib/netcdf/cdm_node.rb +71 -0
- data/lib/netcdf/dimension.rb +146 -0
- data/lib/netcdf/file.rb +253 -0
- data/lib/netcdf/file_writer.rb +474 -0
- data/lib/netcdf/group.rb +205 -0
- data/lib/netcdf/netcdf.rb +151 -0
- data/lib/netcdf/variable.rb +520 -0
- data/test/colt/test_complete.rb +1 -2
- data/test/colt/test_double_matrix2d.rb +186 -0
- data/test/colt/test_float_matrix2d.rb +171 -0
- data/test/colt/test_math.rb +21 -0
- data/test/colt/test_matrix.rb +172 -0
- data/test/complete.rb +9 -1
- data/test/env.rb +11 -1
- data/test/mdarray/test_complete.rb +2 -0
- data/test/mdarray/test_creation.rb +19 -28
- data/test/mdarray/test_non_numeric.rb +97 -0
- data/test/mdarray/test_sections.rb +94 -0
- data/test/mdarray/test_views.rb +23 -1
- data/test/netcdf/netcdfwriter.rb +197 -0
- data/test/netcdf/test_complete.rb +27 -0
- data/test/netcdf/test_netcdf.rb +331 -0
- data/test/netcdf/test_redefine.rb +120 -0
- data/vendor/incanter.jar +0 -0
- data/vendor/{netcdfAll-4.3.16.jar → netcdfAll-4.3.18.jar} +0 -0
- data/version.rb +1 -1
- metadata +44 -26
- data/vendor/parallelcolt-0.10.0.jar +0 -0
data/lib/mdarray.rb
CHANGED
@@ -66,7 +66,8 @@ require_relative 'env'
|
|
66
66
|
class MDArray
|
67
67
|
include_package "ucar.ma2"
|
68
68
|
include Enumerable
|
69
|
-
|
69
|
+
|
70
|
+
attr_reader :id # an array identifier
|
70
71
|
attr_reader :type
|
71
72
|
attr_reader :nc_array
|
72
73
|
attr_reader :local_index # internal helper index for this array
|
@@ -79,6 +80,13 @@ class MDArray
|
|
79
80
|
|
80
81
|
@numerical = ["numeric", "byte", "short", "int", "long", "float", "double"]
|
81
82
|
@non_numerical = ["boolean", "char", "string", "sequence"]
|
83
|
+
@characters = ('a'..'z').to_a + ('A'..'Z').to_a
|
84
|
+
|
85
|
+
=begin
|
86
|
+
@characters = ('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a
|
87
|
+
@characters = ('A'..'F').to_a + (0..9).to_a
|
88
|
+
@characters = (32..126).to_a.pack('U*').chars.to_a
|
89
|
+
=end
|
82
90
|
|
83
91
|
class << self
|
84
92
|
|
@@ -90,7 +98,8 @@ class MDArray
|
|
90
98
|
attr_accessor :unary_operator
|
91
99
|
attr_accessor :previous_binary_operator
|
92
100
|
attr_accessor :previous_unary_operator
|
93
|
-
|
101
|
+
attr_reader :characters
|
102
|
+
|
94
103
|
end
|
95
104
|
|
96
105
|
MDArray.function_map = Map.new
|
@@ -104,7 +113,8 @@ class MDArray
|
|
104
113
|
#------------------------------------------------------------------------------------
|
105
114
|
|
106
115
|
def initialize(type, storage, section = false)
|
107
|
-
|
116
|
+
|
117
|
+
@id = (0..8).map{MDArray.characters.sample}.join
|
108
118
|
@type = type
|
109
119
|
@nc_array = storage
|
110
120
|
@local_index = Counter.new(self)
|
@@ -416,6 +426,44 @@ class MDArray
|
|
416
426
|
|
417
427
|
end
|
418
428
|
|
429
|
+
#------------------------------------------------------------------------------------
|
430
|
+
#
|
431
|
+
#------------------------------------------------------------------------------------
|
432
|
+
|
433
|
+
private
|
434
|
+
|
435
|
+
#------------------------------------------------------------------------------------
|
436
|
+
#
|
437
|
+
#------------------------------------------------------------------------------------
|
438
|
+
|
439
|
+
def self.get_ncarray_type(nc_array)
|
440
|
+
|
441
|
+
if (nc_array.is_a? ArrayDouble)
|
442
|
+
"double"
|
443
|
+
elsif (nc_array.is_a? ArrayFloat)
|
444
|
+
"float"
|
445
|
+
elsif (nc_array.is_a? ArrayLong)
|
446
|
+
"long"
|
447
|
+
elsif (nc_array.is_a? ArrayInt)
|
448
|
+
"int"
|
449
|
+
elsif (nc_array.is_a? ArrayShort)
|
450
|
+
"short"
|
451
|
+
elsif (nc_array.is_a? ArrayByte)
|
452
|
+
"byte"
|
453
|
+
elsif (nc_array.is_a? ArrayChar)
|
454
|
+
"char"
|
455
|
+
elsif (nc_array.is_a? ArrayString)
|
456
|
+
"string"
|
457
|
+
elsif (nc_array.is_a? ArrayBoolean)
|
458
|
+
"boolean"
|
459
|
+
elsif (nc_array.is_a? ArrayObject)
|
460
|
+
"object"
|
461
|
+
else
|
462
|
+
raise "Unknow type for #{nc_array}"
|
463
|
+
end
|
464
|
+
|
465
|
+
end
|
466
|
+
|
419
467
|
end
|
420
468
|
|
421
469
|
require_relative 'mdarray/proc_util'
|
@@ -434,4 +482,7 @@ require_relative 'mdarray/counter'
|
|
434
482
|
require_relative 'mdarray/ruby_stats'
|
435
483
|
require_relative 'mdarray/lazy_mdarray'
|
436
484
|
require_relative 'mdarray/csv'
|
485
|
+
require_relative 'mdarray/section'
|
486
|
+
|
437
487
|
require_relative 'colt/colt'
|
488
|
+
require_relative 'netcdf/netcdf'
|
data/lib/mdarray/access.rb
CHANGED
@@ -70,6 +70,14 @@ class MDArray
|
|
70
70
|
@local_index.get(index)
|
71
71
|
end
|
72
72
|
|
73
|
+
#---------------------------------------------------------------------------------------
|
74
|
+
# Sets a value for a scalar D0 array
|
75
|
+
#---------------------------------------------------------------------------------------
|
76
|
+
|
77
|
+
def get_scalar
|
78
|
+
@local_index.get_scalar
|
79
|
+
end
|
80
|
+
|
73
81
|
#------------------------------------------------------------------------------------
|
74
82
|
#
|
75
83
|
#------------------------------------------------------------------------------------
|
@@ -121,6 +129,14 @@ class MDArray
|
|
121
129
|
@local_index.set(index, value)
|
122
130
|
end
|
123
131
|
|
132
|
+
#---------------------------------------------------------------------------------------
|
133
|
+
# Sets a value for a scalar D0 array
|
134
|
+
#---------------------------------------------------------------------------------------
|
135
|
+
|
136
|
+
def set_scalar(value)
|
137
|
+
@local_index.set_scalar(value)
|
138
|
+
end
|
139
|
+
|
124
140
|
#---------------------------------------------------------------------------------------
|
125
141
|
#
|
126
142
|
#---------------------------------------------------------------------------------------
|
data/lib/mdarray/counter.rb
CHANGED
@@ -178,6 +178,14 @@ class MDArray
|
|
178
178
|
get_at_counter
|
179
179
|
end
|
180
180
|
|
181
|
+
#---------------------------------------------------------------------------------------
|
182
|
+
#
|
183
|
+
#---------------------------------------------------------------------------------------
|
184
|
+
|
185
|
+
def get_scalar
|
186
|
+
@mdarray.nc_array.get
|
187
|
+
end
|
188
|
+
|
181
189
|
#------------------------------------------------------------------------------------
|
182
190
|
# Gets the element at the given counter. Assumes that the counter is of the proper
|
183
191
|
# shape. Also, counter should be an int java array
|
@@ -217,6 +225,14 @@ class MDArray
|
|
217
225
|
set_at_counter(value)
|
218
226
|
end
|
219
227
|
|
228
|
+
#---------------------------------------------------------------------------------------
|
229
|
+
#
|
230
|
+
#---------------------------------------------------------------------------------------
|
231
|
+
|
232
|
+
def set_scalar(value)
|
233
|
+
@mdarray.nc_array.set(value)
|
234
|
+
end
|
235
|
+
|
220
236
|
#------------------------------------------------------------------------------------
|
221
237
|
# Sets value of current counter. Can be done fast, as the current counter is always
|
222
238
|
# in its basic shape.
|
data/lib/mdarray/creation.rb
CHANGED
@@ -91,16 +91,28 @@ class MDArray
|
|
91
91
|
#
|
92
92
|
#------------------------------------------------------------------------------------
|
93
93
|
|
94
|
+
def self.from_jstorage(type, shape, jstorage, section = false)
|
95
|
+
|
96
|
+
dtype = DataType.valueOf(type.upcase)
|
97
|
+
jshape = shape.to_java :int
|
98
|
+
nc_array = Java::UcarMa2.Array.factory(dtype, jshape, jstorage)
|
99
|
+
klass = Object.const_get("#{type.capitalize}MDArray")
|
100
|
+
return klass.new(type, nc_array, section)
|
101
|
+
|
102
|
+
end
|
94
103
|
|
95
104
|
#------------------------------------------------------------------------------------
|
96
105
|
#
|
97
106
|
#------------------------------------------------------------------------------------
|
98
107
|
|
99
108
|
def self.build_from_nc_array(type, nc_array, section = false)
|
109
|
+
if (!type)
|
110
|
+
type = MDArray.get_ncarray_type(nc_array)
|
111
|
+
end
|
100
112
|
klass = Object.const_get("#{type.capitalize}MDArray")
|
101
113
|
return klass.new(type, nc_array, section)
|
102
114
|
end
|
103
|
-
|
115
|
+
|
104
116
|
#------------------------------------------------------------------------------------
|
105
117
|
# Builds a boolean mdarray
|
106
118
|
# @param shape [Array] the shape of the mdarray as a ruby array
|
data/lib/mdarray/lazy_mdarray.rb
CHANGED
@@ -175,12 +175,16 @@ class LazyMDArray < ByteMDArray
|
|
175
175
|
end
|
176
176
|
|
177
177
|
#---------------------------------------------------------------------------------------
|
178
|
-
#
|
179
|
-
# compatible
|
178
|
+
#
|
180
179
|
#---------------------------------------------------------------------------------------
|
181
180
|
|
182
181
|
protected
|
183
182
|
|
183
|
+
#---------------------------------------------------------------------------------------
|
184
|
+
# Validates the expression checking if it can be performed: all dimensions need to be
|
185
|
+
# compatible
|
186
|
+
#---------------------------------------------------------------------------------------
|
187
|
+
|
184
188
|
def validate_fast(*args)
|
185
189
|
|
186
190
|
# test_janino_function
|
@@ -26,6 +26,8 @@
|
|
26
26
|
|
27
27
|
class LazyBinaryOperator < BinaryOperator
|
28
28
|
|
29
|
+
attr_reader :exp # expression in string format
|
30
|
+
|
29
31
|
#---------------------------------------------------------------------------------------
|
30
32
|
#
|
31
33
|
#---------------------------------------------------------------------------------------
|
@@ -35,6 +37,7 @@ class LazyBinaryOperator < BinaryOperator
|
|
35
37
|
@op1 = args.shift
|
36
38
|
@op2 = args.shift
|
37
39
|
@other_args = args
|
40
|
+
@exp = ""
|
38
41
|
|
39
42
|
end
|
40
43
|
|
@@ -52,11 +55,16 @@ class LazyBinaryOperator < BinaryOperator
|
|
52
55
|
if (@op1.is_a? LazyMDArray)
|
53
56
|
lazy.push(@op2)
|
54
57
|
lazy.push(self)
|
58
|
+
# @exp << "(" << @op1.exp << name << @op2.id << ")"
|
55
59
|
else
|
56
60
|
lazy = LazyMDArray.new
|
57
61
|
lazy.push(@op1)
|
58
62
|
lazy.push(@op2)
|
59
63
|
lazy.push(self)
|
64
|
+
# p @op1.id
|
65
|
+
# p @op2.id
|
66
|
+
# p @name
|
67
|
+
# @exp << "(" << @op1.id << name << @op2.id << ")"
|
60
68
|
end
|
61
69
|
|
62
70
|
return lazy
|
data/lib/mdarray/printing.rb
CHANGED
@@ -77,8 +77,17 @@ class MDArray
|
|
77
77
|
#------------------------------------------------------------------------------------
|
78
78
|
|
79
79
|
def print
|
80
|
-
|
80
|
+
|
81
|
+
case rank
|
82
|
+
when 0
|
83
|
+
print0d
|
84
|
+
when 1
|
85
|
+
print1d
|
86
|
+
else
|
87
|
+
printnd
|
88
|
+
end
|
81
89
|
Kernel.print "\n"
|
90
|
+
|
82
91
|
end
|
83
92
|
|
84
93
|
#------------------------------------------------------------------------------------
|
@@ -125,6 +134,14 @@ class MDArray
|
|
125
134
|
|
126
135
|
end
|
127
136
|
|
137
|
+
#------------------------------------------------------------------------------------
|
138
|
+
#
|
139
|
+
#------------------------------------------------------------------------------------
|
140
|
+
|
141
|
+
def print0d
|
142
|
+
Kernel.print(@nc_array.get())
|
143
|
+
end
|
144
|
+
|
128
145
|
#------------------------------------------------------------------------------------
|
129
146
|
#
|
130
147
|
#------------------------------------------------------------------------------------
|
@@ -158,8 +175,6 @@ class MDArray
|
|
158
175
|
end
|
159
176
|
end
|
160
177
|
|
161
|
-
p "axes: #{axes}, slice: #{slice}, sizes: #{sizes}"
|
162
|
-
|
163
178
|
counter.each_along_axes(axes) do |ct, axis|
|
164
179
|
section(ct, sizes)
|
165
180
|
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
##########################################################################################
|
4
|
+
# Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
|
5
|
+
# and distribute this software and its documentation, without fee and without a signed
|
6
|
+
# licensing agreement, is hereby granted, provided that the above copyright notice, this
|
7
|
+
# paragraph and the following two paragraphs appear in all copies, modifications, and
|
8
|
+
# distributions.
|
9
|
+
#
|
10
|
+
# IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
11
|
+
# INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
12
|
+
# THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
|
13
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
14
|
+
#
|
15
|
+
# RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
16
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
|
17
|
+
# SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
|
18
|
+
# RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
19
|
+
# OR MODIFICATIONS.
|
20
|
+
##########################################################################################
|
21
|
+
|
22
|
+
class MDArray
|
23
|
+
|
24
|
+
class Section
|
25
|
+
include_package "ucar.ma2"
|
26
|
+
|
27
|
+
attr_reader :netcdf_elmt
|
28
|
+
|
29
|
+
#-------------------------------------------------------------------------------------
|
30
|
+
#
|
31
|
+
#-------------------------------------------------------------------------------------
|
32
|
+
|
33
|
+
def initialize(netcdf_section)
|
34
|
+
@netcdf_elmt = netcdf_section
|
35
|
+
end
|
36
|
+
|
37
|
+
#-------------------------------------------------------------------------------------
|
38
|
+
# Builds a section by passing the proper section definition. The following itens can
|
39
|
+
# be part of the section definition
|
40
|
+
# shape
|
41
|
+
# origin
|
42
|
+
# size
|
43
|
+
# stride
|
44
|
+
# range
|
45
|
+
# section
|
46
|
+
# spec
|
47
|
+
#-------------------------------------------------------------------------------------
|
48
|
+
|
49
|
+
def self.build(*args)
|
50
|
+
|
51
|
+
opts = Map.options(args)
|
52
|
+
|
53
|
+
shape = opts.getopt(:shape)
|
54
|
+
origin = opts.getopt(:origin)
|
55
|
+
size = opts.getopt(:size)
|
56
|
+
stride = opts.getopt(:stride)
|
57
|
+
range = opts.getopt(:range)
|
58
|
+
section = opts.getopt(:section)
|
59
|
+
spec = opts.getopt(:spec)
|
60
|
+
|
61
|
+
if (spec)
|
62
|
+
new(Java::UcarMa2::Section.new(spec))
|
63
|
+
elsif (shape)
|
64
|
+
if (origin)
|
65
|
+
new(Java::UcarMa2::Section.new(origin.to_java(:int), shape.to_java(:int)))
|
66
|
+
else
|
67
|
+
new(Java::UcarMa2::Section.new(shape.to_java(:int)))
|
68
|
+
end
|
69
|
+
elsif (origin)
|
70
|
+
if (!size || !stride)
|
71
|
+
raise "Invalid section definition, size and stride are required"
|
72
|
+
end
|
73
|
+
new(Java::UcarMa2::Section.new(origin.to_java(:int), size.to_java(:int),
|
74
|
+
stride.to_java(:int)))
|
75
|
+
elsif (range)
|
76
|
+
new(Java::UcarMa2::Section.new(range))
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
#-------------------------------------------------------------------------------------
|
82
|
+
#
|
83
|
+
#-------------------------------------------------------------------------------------
|
84
|
+
|
85
|
+
def print
|
86
|
+
p @netcdf_elmt.toString()
|
87
|
+
end
|
88
|
+
|
89
|
+
#-------------------------------------------------------------------------------------
|
90
|
+
#
|
91
|
+
#-------------------------------------------------------------------------------------
|
92
|
+
|
93
|
+
def to_s
|
94
|
+
@netcdf_elmt.toString()
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
|
@@ -0,0 +1,154 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
##########################################################################################
|
4
|
+
# Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
|
5
|
+
# and distribute this software and its documentation, without fee and without a signed
|
6
|
+
# licensing agreement, is hereby granted, provided that the above copyright notice, this
|
7
|
+
# paragraph and the following two paragraphs appear in all copies, modifications, and
|
8
|
+
# distributions.
|
9
|
+
#
|
10
|
+
# IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
11
|
+
# INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
12
|
+
# THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
|
13
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
14
|
+
#
|
15
|
+
# RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
16
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
|
17
|
+
# SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
|
18
|
+
# RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
19
|
+
# OR MODIFICATIONS.
|
20
|
+
##########################################################################################
|
21
|
+
|
22
|
+
#=========================================================================================
|
23
|
+
#
|
24
|
+
#=========================================================================================
|
25
|
+
|
26
|
+
class NetCDF
|
27
|
+
|
28
|
+
#=======================================================================================
|
29
|
+
# An Attribute has a name and a value, used for associating arbitrary metadata with
|
30
|
+
# a Variable or a Group. The value can be a one dimensional array of Strings or
|
31
|
+
# numeric values.
|
32
|
+
# Attributes are immutable.
|
33
|
+
#=======================================================================================
|
34
|
+
|
35
|
+
class Attribute < CDMNode
|
36
|
+
|
37
|
+
#------------------------------------------------------------------------------------
|
38
|
+
#
|
39
|
+
#------------------------------------------------------------------------------------
|
40
|
+
|
41
|
+
def data_type
|
42
|
+
@netcdf_elmt.getDataType().toString()
|
43
|
+
end
|
44
|
+
|
45
|
+
#------------------------------------------------------------------------------------
|
46
|
+
#
|
47
|
+
#------------------------------------------------------------------------------------
|
48
|
+
|
49
|
+
def length
|
50
|
+
@netcdf_elmt.getLength()
|
51
|
+
end
|
52
|
+
|
53
|
+
#------------------------------------------------------------------------------------
|
54
|
+
#
|
55
|
+
#------------------------------------------------------------------------------------
|
56
|
+
|
57
|
+
def numeric_value(index = 0)
|
58
|
+
@netcdf_elmt.getNumericValue(index)
|
59
|
+
end
|
60
|
+
|
61
|
+
#------------------------------------------------------------------------------------
|
62
|
+
#
|
63
|
+
#------------------------------------------------------------------------------------
|
64
|
+
|
65
|
+
def string_value(index = 0)
|
66
|
+
@netcdf_elmt.getStringValue(index)
|
67
|
+
end
|
68
|
+
|
69
|
+
#------------------------------------------------------------------------------------
|
70
|
+
#
|
71
|
+
#------------------------------------------------------------------------------------
|
72
|
+
|
73
|
+
def value(index = 0)
|
74
|
+
@netcdf_elmt.getValue(index)
|
75
|
+
end
|
76
|
+
|
77
|
+
#------------------------------------------------------------------------------------
|
78
|
+
#
|
79
|
+
#------------------------------------------------------------------------------------
|
80
|
+
|
81
|
+
def array?
|
82
|
+
@netcdf_elmt.isArray()
|
83
|
+
end
|
84
|
+
|
85
|
+
#------------------------------------------------------------------------------------
|
86
|
+
#
|
87
|
+
#------------------------------------------------------------------------------------
|
88
|
+
|
89
|
+
def string?
|
90
|
+
@netcdf_elmt.isString()
|
91
|
+
end
|
92
|
+
|
93
|
+
#------------------------------------------------------------------------------------
|
94
|
+
#
|
95
|
+
#------------------------------------------------------------------------------------
|
96
|
+
|
97
|
+
def unsigned?
|
98
|
+
@netcdf_elmt.isUnsigned()
|
99
|
+
end
|
100
|
+
|
101
|
+
#------------------------------------------------------------------------------------
|
102
|
+
#
|
103
|
+
#------------------------------------------------------------------------------------
|
104
|
+
|
105
|
+
def to_string(strict = false)
|
106
|
+
@netcdf_elmt.toString(strict)
|
107
|
+
end
|
108
|
+
|
109
|
+
#------------------------------------------------------------------------------------
|
110
|
+
# Needs to be correctly rubyfied
|
111
|
+
#------------------------------------------------------------------------------------
|
112
|
+
|
113
|
+
def write_cdl(formater, strict = false)
|
114
|
+
@netcdf_elmt.write_cdl(formater, strict)
|
115
|
+
end
|
116
|
+
|
117
|
+
end # Attribute
|
118
|
+
|
119
|
+
#=======================================================================================
|
120
|
+
#
|
121
|
+
#=======================================================================================
|
122
|
+
|
123
|
+
class AttributeWriter < Attribute
|
124
|
+
|
125
|
+
#------------------------------------------------------------------------------------
|
126
|
+
#
|
127
|
+
#------------------------------------------------------------------------------------
|
128
|
+
|
129
|
+
def self.build(name, val, type = "int")
|
130
|
+
|
131
|
+
type = type.to_sym
|
132
|
+
value = val
|
133
|
+
if (val.is_a? Numeric)
|
134
|
+
value = val.to_java(type)
|
135
|
+
elsif (val.is_a? Array)
|
136
|
+
value = Array.new
|
137
|
+
val.each do |elmt|
|
138
|
+
if (elmt.is_a? Numeric)
|
139
|
+
value << elmt.to_java(type)
|
140
|
+
else
|
141
|
+
value << elmt
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
NetCDF::Attribute.new(Java::UcarNc2::Attribute.new(name, value))
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
end # AttributeWriter
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
|