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 57 58 59 60 61 62 63 64 65 66 67
|
require "numru/dcl"
require "numru/netcdf"
include NumRu
include NMath
## < create a sample netcdf file >
def write_file
file = NetCDF.create("test.nc")
nx, ny = 21, 21
xdim = file.def_dim("x",nx)
ydim = file.def_dim("y",ny)
x = file.def_var("x","sfloat",["x"])
y = file.def_var("y","sfloat",["y"])
var = file.def_var("var","float",["x","y"])
var.put_att("long_name","test variable")
file.enddef
vx = NArray.float(nx).indgen! * (2*(Math::PI)*1.5/(nx-1))
vy = NArray.float(ny).indgen! * (2*(Math::PI)*1.0/(ny-1))
x.put( vx )
y.put( vy )
sx = sin( vx )
sy = sin( vy )
z = NArray.float(nx,ny)
for j in 0..ny-1
z[true,j] = sx * sy[j] + 0.00001
end
var.put(z)
file.close
print `ncdump -h test.nc`
end
## < read the file and plot >
def draw_graph
file = NetCDF.open("test.nc")
vx = file.var("x")
vy = file.var("y")
vz = file.var("var")
x = vx.get
y = vy.get
z = vz.get
file.close
#DCL.swlset('ldump',1)
DCL.gropn(1)
DCL.grfrm
DCL.usspnt(x, y)
DCL.uspfit
DCL.usdaxs
DCL.sglset("lsoftf",false)
DCL.uegtlb(z, -20) # set the number of levels
DCL.uelset("ltone",true)
DCL.uetone(z)
DCL.udcntz(z)
DCL.grcls
end
###(main)###
write_file
draw_graph
###(main)###
|