File: putatt.rb

package info (click to toggle)
ruby-netcdf 0.6.6-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,184 kB
  • ctags: 882
  • sloc: ansic: 3,968; ruby: 1,661; makefile: 9; csh: 6
file content (56 lines) | stat: -rw-r--r-- 1,510 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'numru/netcdf'
include NumRu
s = 'tmp.nc'
f = NetCDF.create(s)
d = f.def_dim('x',5)
v = f.def_var('x','sfloat',[d])

require 'date'
att = f.put_att("history", Date.today.to_s )
p att.get, f.att("history").get
att = f.put_att("int_att",123)
att = f.put_att("sfloat_att",1.0/3.0,'sfloat')
att = f.put_att("sfloat_att2",2.0/3.0,NArray::SFLOAT)
att = v.put_att("long_name",'test variable')
att = v.put_att("int_att",123)
p att.get, v.att("int_att").get
att = v.put_att("float_att",1.0/3.0)
att = v.put_att("float_array",[0.1, 0.2, 30])
att = v.put_att("sfloat_narray",NArray.sfloat(3).indgen!/3)
att = v.put_att("float_narray",NArray.float(3).indgen!)
att = v.put_att("sint_narray",NArray.sint(3).indgen!)
att = v.put_att("int2float",10,'float')
att = att = v.put_att("dummy",10,'float')
att.put('changed to text')
att.name = 'changed'
begin
   v.put_att("destined_to_fail",9.8,'complex')
rescue
   print "*1* exception raised as expected -- (",
         __FILE__,":",__LINE__,") ", $!,"\n"
end
begin
   v.put_att("destined_to_fail",9.8,'string')
rescue
   print "*2* exception raised as expected -- (",
         __FILE__,":",__LINE__,") ", $!,"\n"
end

begin
   v.put_att("destined_to_fail",'hello','int')
rescue
   print "*3* exception raised as expected -- (",
         __FILE__,":",__LINE__,") ", $!,"\n"
end

begin
   v.put_att("destined_to_fail",[10,30,'sss'])
rescue
   print "*4* exception raised as expected -- (",
         __FILE__,":",__LINE__,") ", $!,"\n"
end


f.close

print `ncdump tmp.nc`