gentooboontoo-ruby-netcdf 0.6.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +396 -0
- data/INSTALL +62 -0
- data/LICENSE.txt +59 -0
- data/demo/README +14 -0
- data/demo/demo1-create-alt.rb +35 -0
- data/demo/demo1-create.rb +35 -0
- data/demo/demo2-graphic.rb +67 -0
- data/demo/demo3-ncepclim.rb +178 -0
- data/demo/demo4-copy.rb +32 -0
- data/doc/README_JP.txt +152 -0
- data/doc/Ref_man.html +1482 -0
- data/doc/Ref_man.rd +1312 -0
- data/doc/Ref_man_jp.html +1445 -0
- data/doc/Ref_man_jp.rd +1276 -0
- data/doc/to_html +7 -0
- data/ext/extconf.rb +134 -0
- data/ext/netcdfraw.c +4614 -0
- data/lib/numru/netcdf.rb +792 -0
- data/lib/numru/netcdf_miss.rb +203 -0
- data/test/aref_aset.rb +37 -0
- data/test/char_var.rb +25 -0
- data/test/clone.rb +54 -0
- data/test/create_tmp.rb +15 -0
- data/test/def_var_with_dim.rb +14 -0
- data/test/factor_offset.rb +53 -0
- data/test/putatt.cdl +23 -0
- data/test/putatt.rb +56 -0
- data/test/test.cdl +31 -0
- data/test/test.rb +192 -0
- data/test/type.rb +13 -0
- metadata +128 -0
@@ -0,0 +1,203 @@
|
|
1
|
+
require "numru/netcdf"
|
2
|
+
require "narray_miss"
|
3
|
+
|
4
|
+
module NumRu
|
5
|
+
|
6
|
+
class NetCDFVar
|
7
|
+
|
8
|
+
def get_with_miss(*args)
|
9
|
+
__interpret_missing_params if !defined?(@missval)
|
10
|
+
data = simple_get(*args)
|
11
|
+
if @vmin || @vmax
|
12
|
+
if @vmin
|
13
|
+
mask = (data >= @vmin)
|
14
|
+
mask = mask.and(data <= @vmax) if @vmax
|
15
|
+
else
|
16
|
+
mask = (data <= @vmax)
|
17
|
+
end
|
18
|
+
data = NArrayMiss.to_nam(data, mask)
|
19
|
+
elsif @missval # only missing_value is present.
|
20
|
+
mask = (data.ne(@missval))
|
21
|
+
data = NArrayMiss.to_nam(data, mask)
|
22
|
+
end
|
23
|
+
data
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_with_miss_and_scaling(*args)
|
27
|
+
__interpret_missing_params if !defined?(@missval)
|
28
|
+
data = simple_get(*args)
|
29
|
+
if @vmin || @vmax
|
30
|
+
if @vmin
|
31
|
+
mask = (data >= @vmin)
|
32
|
+
mask = mask.and(data <= @vmax) if @vmax
|
33
|
+
else
|
34
|
+
mask = (data <= @vmax)
|
35
|
+
end
|
36
|
+
data = NArrayMiss.to_nam(data, mask)
|
37
|
+
elsif @missval # only missing_value is present.
|
38
|
+
mask = (data.ne(@missval))
|
39
|
+
data = NArrayMiss.to_nam(data, mask)
|
40
|
+
end
|
41
|
+
data = unpack( data )
|
42
|
+
data
|
43
|
+
end
|
44
|
+
|
45
|
+
def put_with_miss(data, *args)
|
46
|
+
if data.is_a?( NArrayMiss )
|
47
|
+
__interpret_missing_params if !defined?(@missval)
|
48
|
+
if @missval
|
49
|
+
simple_put(data.to_na(@missval), *args)
|
50
|
+
else
|
51
|
+
simple_put(data.to_na, *args)
|
52
|
+
end
|
53
|
+
else
|
54
|
+
simple_put(data, *args)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def put_with_miss_and_scaling(data, *args)
|
59
|
+
if data.is_a?( NArrayMiss )
|
60
|
+
__interpret_missing_params if !defined?(@missval)
|
61
|
+
if @missval
|
62
|
+
data = pack( data )
|
63
|
+
data = data.to_na(@missval)
|
64
|
+
else
|
65
|
+
data = pack( data )
|
66
|
+
data = data.to_na
|
67
|
+
end
|
68
|
+
simple_put(data, *args)
|
69
|
+
else
|
70
|
+
scaled_put(data, *args)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
######### private ##########
|
75
|
+
|
76
|
+
def __interpret_missing_params
|
77
|
+
# Interprets the specification of missing data,
|
78
|
+
# either by valid_range, (valid_min and/or valid_max), or missing_value.
|
79
|
+
# (unlike the NetCDF User's guide (NUG), missing_value is interpreted,
|
80
|
+
# but valid_* has a higher precedence.)
|
81
|
+
# Always sets @missval whether missing_value is defined or not,
|
82
|
+
# since it will be used as a fill value for data missing.
|
83
|
+
#
|
84
|
+
@vmin = att('valid_min')
|
85
|
+
@vmin = @vmin.get if @vmin # kept in a NArray(size==1) to consv type
|
86
|
+
@vmax = att('valid_max')
|
87
|
+
@vmax = @vmax.get if @vmax # kept in a NArray(size==1) to consv type
|
88
|
+
vrange = att('valid_range')
|
89
|
+
vrange = vrange.get if vrange
|
90
|
+
if vrange
|
91
|
+
vrange.sort!
|
92
|
+
@vmin = vrange[0..0] # kept in... (same)
|
93
|
+
@vmax = vrange[-1..-1] # kept in... (same)
|
94
|
+
end
|
95
|
+
@missval = att('missing_value') || att('_FillValue')
|
96
|
+
@missval = @missval.get if @missval # kept in... (same)
|
97
|
+
|
98
|
+
sf = att('scale_factor')
|
99
|
+
ao = att('add_offset')
|
100
|
+
if ( sf || ao )
|
101
|
+
## Both NUG & CF conventions requires to specify the valid
|
102
|
+
## range with respect to the external (i.e. packed) values.
|
103
|
+
## However, some conventions require specification
|
104
|
+
## with respect to unpacked values. The following
|
105
|
+
## is to support such cases as well:
|
106
|
+
thres_tp = [ self.typecode, NArray::LINT ].max
|
107
|
+
@missval = pack(@missval) if @missval && @missval.typecode > thres_tp
|
108
|
+
@vmin = pack(@vmin) if @vmin && @vmin.typecode > thres_tp
|
109
|
+
@vmax = pack(@vmax) if @vmax && @vmax.typecode > thres_tp
|
110
|
+
end
|
111
|
+
|
112
|
+
if @missval
|
113
|
+
if @vmin && @vmax
|
114
|
+
if @vmin[0] <= @missval[0] && @missval[0] <= @vmax[0]
|
115
|
+
warn "WARNING: missing_value #{@missval[0]} is in the valid range #{@vmin[0]}..#{@vmax[0]} --> will be ignored (#{__FILE__}:#{__LINE__})"
|
116
|
+
end
|
117
|
+
else
|
118
|
+
if @vmin && @missval[0] >= @vmin[0]
|
119
|
+
warn "WARNING: missing_value #{@missval[0]} >= valid min #{@vmin[0]} --> will be ignored (#{__FILE__}:#{__LINE__})"
|
120
|
+
elsif @vmax && @missval[0] <= @vmax[0]
|
121
|
+
warn "WARNING: missing_value #{@missval[0]} <= valid min #{@vmin[0]} --> will be ignored (#{__FILE__}:#{__LINE__})"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
else
|
125
|
+
realtc = NArray::SFLOAT
|
126
|
+
if @vmin
|
127
|
+
if @vmin[0] >= 0
|
128
|
+
@missval = ( @vmin.typecode>=realtc ? 0.99*@vmin : @vmin-1 )
|
129
|
+
else
|
130
|
+
@missval = ( @vmin.typecode>=realtc ? 1.01*@vmin : @vmin-1 )
|
131
|
+
end
|
132
|
+
elsif @vmax
|
133
|
+
if @vmax[0] >= 0
|
134
|
+
@missval = ( @vmax.typecode>=realtc ? 1.01*@vmax : @vmax+1 )
|
135
|
+
else
|
136
|
+
@missval = ( @vmax.typecode>=realtc ? 0.99*@vmax : @vmax+1 )
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
private :__interpret_missing_params
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
if $0 == __FILE__
|
150
|
+
include NumRu
|
151
|
+
|
152
|
+
filename = "tmp.nc"
|
153
|
+
print "creating ",filename,"...\n"
|
154
|
+
file=NetCDF.create(filename)
|
155
|
+
nx = 10
|
156
|
+
dimx = file.def_dim("x",nx)
|
157
|
+
xf = file.def_var("xf","sfloat",[dimx])
|
158
|
+
xfn = file.def_var("xfn","sfloat",[dimx])
|
159
|
+
xf.put_att("valid_range",[-1e12,1e12])
|
160
|
+
f = 10 ** (2*NArray.sfloat(nx).indgen!)
|
161
|
+
xr = file.def_var("xr","sint",[dimx])
|
162
|
+
xr.put_att("valid_max",[0.5])
|
163
|
+
xr.put_att("scale_factor",1e-4)
|
164
|
+
xr.put_att("add_offset",0.5)
|
165
|
+
xr2 = file.def_var("xr2","sint",[dimx])
|
166
|
+
xr2.put_att("valid_max",NArray.sint(1).fill!(1000))
|
167
|
+
xr2.put_att("scale_factor",1e-4)
|
168
|
+
xr2.put_att("add_offset",0.5)
|
169
|
+
r = NArray.sfloat(nx).indgen!/nx
|
170
|
+
file.enddef
|
171
|
+
xf.put(f)
|
172
|
+
xfn.put(f)
|
173
|
+
xr.scaled_put(r)
|
174
|
+
file.close
|
175
|
+
|
176
|
+
file = NetCDF.open(filename,'r+')
|
177
|
+
xf = file.var('xf')
|
178
|
+
xfn = file.var('xfn')
|
179
|
+
p "f0"
|
180
|
+
xf.get.each{|v| print "#{v} "} ; print "\n"
|
181
|
+
p( 'f1', nam = xf.get_with_miss )
|
182
|
+
def xf.get(*args); get_with_miss(*args); end
|
183
|
+
p( 'f12', xf[2..-3].to_na )
|
184
|
+
p( 'fn10', xfn.get_with_miss )
|
185
|
+
p( 'fn11', xfn.get_with_miss_and_scaling )
|
186
|
+
nam.invalidation([0,1])
|
187
|
+
p 'f2', nam
|
188
|
+
xf.put_with_miss(nam)
|
189
|
+
p( 'f3', xf.get_with_miss )
|
190
|
+
xr = file.var('xr')
|
191
|
+
p "r0"
|
192
|
+
xr.simple_get.each{|v| print "#{v} "} ; print "\n"
|
193
|
+
p( 'r1', xr.get_with_miss_and_scaling )
|
194
|
+
def xr.get(*args); get_with_miss_and_scaling(*args); end
|
195
|
+
def xr.put(*args); put_with_miss_and_scaling(*args); end
|
196
|
+
#xr[0..3] = xr[0..3]*10
|
197
|
+
p( 'r2', xr.get_with_miss_and_scaling )
|
198
|
+
p 'r',r
|
199
|
+
xr2.put_with_miss_and_scaling(r)
|
200
|
+
p 'xr2',xr2.get_with_miss_and_scaling
|
201
|
+
file.close
|
202
|
+
print "** ncdump tmp.nc **\n", `ncdump tmp.nc`
|
203
|
+
end
|
data/test/aref_aset.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'numru/netcdf'
|
2
|
+
include NumRu
|
3
|
+
s = 'tmp.nc'
|
4
|
+
f = NetCDF.create(s)
|
5
|
+
f.redef
|
6
|
+
dx = f.def_dim('x',5)
|
7
|
+
dy = f.def_dim('y',3)
|
8
|
+
v = f.def_var('x','sfloat',[dx])
|
9
|
+
v2 = f.def_var('x2',NArray::SFLOAT,[dx])
|
10
|
+
vxy = f.def_var('xy','sfloat',[dx,dy])
|
11
|
+
f.enddef
|
12
|
+
v.put([1,2,3,4,5])
|
13
|
+
p 'testing []= ...'
|
14
|
+
v[{0..3=>2}]=[100,500]
|
15
|
+
v[1]=999
|
16
|
+
v[3..4]=[-99,-99]
|
17
|
+
v2.put(666)
|
18
|
+
v2[0..2]=777
|
19
|
+
vxy.put(NArray.sfloat(5,3).indgen!)
|
20
|
+
vxy[[2,0],[0,2,1]] = [[1,2],[3,4],[5,6]]
|
21
|
+
vxy[1,[2,0,1]] = [10,20,30]
|
22
|
+
vxy[[4,3],2] = [100,200]
|
23
|
+
|
24
|
+
f.close
|
25
|
+
|
26
|
+
f = NetCDF.open(s)
|
27
|
+
v = f.var('x')
|
28
|
+
p 'testing [] ...'
|
29
|
+
p '*0*',v[{0..3=>2}]
|
30
|
+
p '*1*',v[1]
|
31
|
+
p '*2*',v[3..4],v.rank
|
32
|
+
p '*3*',v[[2,0,0]]
|
33
|
+
vxy = f.var('xy')
|
34
|
+
p '*4*',vxy[[2,0],[0,2,1]]
|
35
|
+
p '*5*',vxy[1,[2,0,1]]
|
36
|
+
p '*6*',vxy[[4,3],2]
|
37
|
+
f.close
|
data/test/char_var.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
## test of "char" variables
|
2
|
+
|
3
|
+
require 'numru/netcdf'
|
4
|
+
include NumRu
|
5
|
+
s = 'tmp.nc'
|
6
|
+
f = NetCDF.create(s)
|
7
|
+
d = f.def_dim('x',5)
|
8
|
+
v = f.def_var('x','char',[d])
|
9
|
+
tv = f.def_var('text','char',[d])
|
10
|
+
f.enddef
|
11
|
+
v.put( NArray.byte(5).indgen! )
|
12
|
+
tv.put( NArray.to_na("hello","byte",5) )
|
13
|
+
tv.put( NArray.to_na("LO","byte",2), 'start'=>[3] )
|
14
|
+
tv.put( NArray.to_na("H","byte",1), 'index'=>[0] )
|
15
|
+
f.close
|
16
|
+
|
17
|
+
f = NetCDF.open(s)
|
18
|
+
v = f.var('x')
|
19
|
+
p v.get
|
20
|
+
tv = f.var('text')
|
21
|
+
p tv.get
|
22
|
+
p tv.get.to_s
|
23
|
+
|
24
|
+
|
25
|
+
|
data/test/clone.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'numru/netcdf'
|
2
|
+
include NumRu
|
3
|
+
s = 'tmp.nc'
|
4
|
+
#f = NetCDF.new(s,'rw')
|
5
|
+
f = NetCDF.create(s)
|
6
|
+
f.redef
|
7
|
+
d = f.def_dim('x',3)
|
8
|
+
v = f.def_var('x','sfloat',[d])
|
9
|
+
a = f.put_att('long_name','xx')
|
10
|
+
f.enddef
|
11
|
+
v.put([1,2,3])
|
12
|
+
f.taint
|
13
|
+
f.freeze
|
14
|
+
f2 = f.clone
|
15
|
+
p 'netcdf clone'
|
16
|
+
p f.path, f2.path
|
17
|
+
p f.tainted?, f2.tainted?, f.frozen?, f2.frozen?
|
18
|
+
|
19
|
+
p 'netcdf dup'
|
20
|
+
f3 = f.dup
|
21
|
+
p f.tainted?, f3.tainted?, f.frozen?, f3.frozen?
|
22
|
+
|
23
|
+
p 'netcdfdim'
|
24
|
+
d.taint
|
25
|
+
d2 = d.clone
|
26
|
+
d3 = d.dup
|
27
|
+
p d.tainted?, d2.tainted?, d3.tainted?
|
28
|
+
|
29
|
+
p 'netcdfvar'
|
30
|
+
v.taint
|
31
|
+
v2 = v.clone
|
32
|
+
v3 = v.dup
|
33
|
+
p v.tainted?, v2.tainted?, v3.tainted?
|
34
|
+
|
35
|
+
p 'netcdfatt'
|
36
|
+
a.taint
|
37
|
+
a2 = a.clone
|
38
|
+
a3 = a.dup
|
39
|
+
p a.tainted?, a2.tainted?, a3.tainted?
|
40
|
+
|
41
|
+
f.close
|
42
|
+
|
43
|
+
p 'narray (for reference)'
|
44
|
+
a = NArray.float(3)
|
45
|
+
a.taint
|
46
|
+
b = a.clone
|
47
|
+
p a.tainted?, b.tainted?
|
48
|
+
b = a.dup
|
49
|
+
p a.tainted?, b.tainted?
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
data/test/create_tmp.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'numru/netcdf'
|
2
|
+
|
3
|
+
$DEBUG = true
|
4
|
+
include NumRu
|
5
|
+
file = NetCDF.create_tmp
|
6
|
+
file.def_dim('x',5)
|
7
|
+
file.put_att("history", __FILE__ )
|
8
|
+
p file.path
|
9
|
+
p file.att("history").get
|
10
|
+
print "environment variable TEMP ="+(ENV['TEMP'] || '')+"\n"
|
11
|
+
file2=file
|
12
|
+
print "000\n"
|
13
|
+
file.close
|
14
|
+
GC.start
|
15
|
+
print "aaa\n"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'numru/netcdf'
|
2
|
+
include NumRu
|
3
|
+
file = NetCDF.create("tmp.nc")
|
4
|
+
var1 = file.def_var_with_dim("var1","sfloat",[6],["x"])
|
5
|
+
var2 = file.def_var_with_dim("var2","sfloat",[6,3],["x","y"])
|
6
|
+
var3 = file.def_var_with_dim("var3","sfloat",[3],["y"])
|
7
|
+
var3 = file.def_var_with_dim("var4","sfloat",[0],["t"])
|
8
|
+
att = var1.put_att("long_name","test")
|
9
|
+
file.close
|
10
|
+
|
11
|
+
p var1 == nil
|
12
|
+
p file == nil
|
13
|
+
p att == nil
|
14
|
+
p att == att, var1 ==var1, file == file
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'numru/netcdf'
|
2
|
+
include NumRu
|
3
|
+
|
4
|
+
s = 'tmp.nc'
|
5
|
+
f = NetCDF.create(s)
|
6
|
+
|
7
|
+
nx = 10
|
8
|
+
d = f.def_dim('x',nx)
|
9
|
+
v1 = f.def_var('v1','sint',[d])
|
10
|
+
v2 = f.def_var('v2','sint',[d])
|
11
|
+
v3 = f.def_var('v3','int',[d])
|
12
|
+
v1.put_att('scale_factor',0.1,'sfloat')
|
13
|
+
v1.put_att('add_offset',100.0,'sfloat')
|
14
|
+
v2.put_att('scale_factor',0.1,'sfloat')
|
15
|
+
v2.put_att('add_offset',100.0,'sfloat')
|
16
|
+
v3.put_att('scale_factor',0.1,'sfloat')
|
17
|
+
v3.put_att('add_offset',100.0,'sfloat')
|
18
|
+
f.enddef
|
19
|
+
v1.put( NArray.sint(nx).indgen!+100 )
|
20
|
+
v2.scaled_put( NArray.float(nx).indgen!+100 )
|
21
|
+
v3.scaled_put( NArray.float(nx).indgen!+100 )
|
22
|
+
f.close
|
23
|
+
|
24
|
+
|
25
|
+
print "** originally unscaled\n"
|
26
|
+
f = NetCDF.open(s)
|
27
|
+
v1 = f.var('v1')
|
28
|
+
v11 = v1.get
|
29
|
+
v12 = v1.scaled_get
|
30
|
+
p v11
|
31
|
+
p v12
|
32
|
+
|
33
|
+
print "** originally scaled\n"
|
34
|
+
v2 = f.var('v2')
|
35
|
+
v21 = v2.get
|
36
|
+
v22 = v2.scaled_get
|
37
|
+
p v21
|
38
|
+
p v22
|
39
|
+
|
40
|
+
print "** originally sclaed (int --> double)\n"
|
41
|
+
v3 = f.var('v3')
|
42
|
+
v31 = v3.get
|
43
|
+
v32 = v3.scaled_get
|
44
|
+
p v31
|
45
|
+
p v32
|
46
|
+
|
47
|
+
print "** unpack type fixed to sfloat\n"
|
48
|
+
NetCDFVar.unpack_type = NArray::SFLOAT
|
49
|
+
v33 = v3.scaled_get
|
50
|
+
p v33
|
51
|
+
NetCDFVar.unpack_type = NArray::INT
|
52
|
+
v33 = v3.scaled_get
|
53
|
+
p v33
|
data/test/putatt.cdl
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
netcdf tmp {
|
2
|
+
dimensions:
|
3
|
+
x = 5 ;
|
4
|
+
variables:
|
5
|
+
float x(x) ;
|
6
|
+
x:long_name = "test variable" ;
|
7
|
+
x:int_att = 123s ;
|
8
|
+
x:float_att = 0.333333333333333 ;
|
9
|
+
x:float_array = 0.1, 0.2, 30. ;
|
10
|
+
x:sfloat_narray = 0.f, 0.3333333f, 0.6666667f ;
|
11
|
+
x:float_narray = 0., 1., 2. ;
|
12
|
+
x:sint_narray = 0s, 1s, 2s ;
|
13
|
+
x:int2float = 10. ;
|
14
|
+
x:changed = "changed to text" ;
|
15
|
+
|
16
|
+
// global attributes:
|
17
|
+
:history = "2001-12-23" ;
|
18
|
+
:int_att = 123s ;
|
19
|
+
:sfloat_att = 0.3333333f ;
|
20
|
+
data:
|
21
|
+
|
22
|
+
x = _, _, _, _, _ ;
|
23
|
+
}
|
data/test/putatt.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'numru/netcdf'
|
2
|
+
include NumRu
|
3
|
+
s = 'tmp.nc'
|
4
|
+
f = NetCDF.create(s)
|
5
|
+
d = f.def_dim('x',5)
|
6
|
+
v = f.def_var('x','sfloat',[d])
|
7
|
+
|
8
|
+
require 'date'
|
9
|
+
att = f.put_att("history", Date.today.to_s )
|
10
|
+
p att.get, f.att("history").get
|
11
|
+
att = f.put_att("int_att",123)
|
12
|
+
att = f.put_att("sfloat_att",1.0/3.0,'sfloat')
|
13
|
+
att = f.put_att("sfloat_att2",2.0/3.0,NArray::SFLOAT)
|
14
|
+
att = v.put_att("long_name",'test variable')
|
15
|
+
att = v.put_att("int_att",123)
|
16
|
+
p att.get, v.att("int_att").get
|
17
|
+
att = v.put_att("float_att",1.0/3.0)
|
18
|
+
att = v.put_att("float_array",[0.1, 0.2, 30])
|
19
|
+
att = v.put_att("sfloat_narray",NArray.sfloat(3).indgen!/3)
|
20
|
+
att = v.put_att("float_narray",NArray.float(3).indgen!)
|
21
|
+
att = v.put_att("sint_narray",NArray.sint(3).indgen!)
|
22
|
+
att = v.put_att("int2float",10,'float')
|
23
|
+
att = att = v.put_att("dummy",10,'float')
|
24
|
+
att.put('changed to text')
|
25
|
+
att.name = 'changed'
|
26
|
+
begin
|
27
|
+
v.put_att("destined_to_fail",9.8,'complex')
|
28
|
+
rescue
|
29
|
+
print "*1* exception raised as expected -- (",
|
30
|
+
__FILE__,":",__LINE__,") ", $!,"\n"
|
31
|
+
end
|
32
|
+
begin
|
33
|
+
v.put_att("destined_to_fail",9.8,'string')
|
34
|
+
rescue
|
35
|
+
print "*2* exception raised as expected -- (",
|
36
|
+
__FILE__,":",__LINE__,") ", $!,"\n"
|
37
|
+
end
|
38
|
+
|
39
|
+
begin
|
40
|
+
v.put_att("destined_to_fail",'hello','int')
|
41
|
+
rescue
|
42
|
+
print "*3* exception raised as expected -- (",
|
43
|
+
__FILE__,":",__LINE__,") ", $!,"\n"
|
44
|
+
end
|
45
|
+
|
46
|
+
begin
|
47
|
+
v.put_att("destined_to_fail",[10,30,'sss'])
|
48
|
+
rescue
|
49
|
+
print "*4* exception raised as expected -- (",
|
50
|
+
__FILE__,":",__LINE__,") ", $!,"\n"
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
f.close
|
55
|
+
|
56
|
+
print `ncdump tmp.nc`
|