File: demo1-create.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 (35 lines) | stat: -rw-r--r-- 932 bytes parent folder | download | duplicates (7)
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
require "numru/netcdf"
include NumRu

file = NetCDF.create("test.nc")
nx, ny = 10, 5
xdim = file.def_dim("x",nx)
ydim = file.def_dim("y",ny)
tdim = file.def_dim("t",0)
require "date"
file.put_att("history","created by #{$0}  #{Date.today}")

x = file.def_var("x","sfloat",[xdim])
y = file.def_var("y","sfloat",[ydim])
t = file.def_var("t","sfloat",[tdim])
v1 = file.def_var("v1","sfloat",[xdim,ydim])
v1.put_att("long_name","test 1")
v1.put_att("units","1")
v2 = file.def_var("v2","sfloat",[xdim,ydim,tdim])
v2.put_att("long_name","test 2")
v2.put_att("units","1")
file.enddef

x.put( NArray.float(nx).indgen! )
y.put( NArray.float(ny).indgen! )

z = NArray.float(nx,ny).indgen!*0.1
v1.put(z)
v1.put( NArray.float(nx).add!(20), "start"=>[0,2],"end"=>[-1,2])
v2.put(z, "start"=>[0,0,0],"end"=>[-1,-1,0])
t.put( 0, "index"=>[0])
v2.put(-z, "start"=>[0,0,1],"end"=>[-1,-1,1])
t.put( 1, "index"=>[1])

file.close
print `ncdump test.nc`