test.rb 1.74 KB
Newer Older
Ralf Mueller's avatar
Ralf Mueller committed
1
require './CdiObj'
Uwe Schulzweida's avatar
Uwe Schulzweida committed
2
3
4
include CdiObj
require "pp"

5
ifile = ARGV[0].nil? ? "../testdata/mulval.grb" : ARGV[0]
Uwe Schulzweida's avatar
Uwe Schulzweida committed
6

7
puts "Reading file: #{ifile}"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
cdi = Cdi.new(ifile);

puts "Stream: #{cdi.streamID} vlistID:#{cdi.vlistID} nvars:#{cdi.nvars}"

puts "#========== TAXES ====================================#"
cdi.taxes.each {|k,v| 
  puts k.to_s+": " + cdi.taxes[k].ntsteps.to_s
}
puts "#========== GRIDS ====================================#"
cdi.grids.each {|k,v| 
  puts [k.to_s+": ",
        v.size.to_s,
        v.xname,
        v.yname,
        v.ylongname].join(" ")
}

puts "#========== ZAXES ====================================#"
cdi.zaxes.each {|k,v|
  puts [k.to_s+": ",
        cdi.zaxes[k].size.to_s,
        cdi.zaxes[k].name,
        cdi.zaxes[k].units].join(" ")
}

puts "#========== VARIABLES ================================#"
cdi.variables.each_with_index {|k,i| 
  print k.name[0,5] + " " + k.size.to_s + " "
  puts if i%16==0
}
cdi.variables.each_with_index {|k,i| 
  print k.missval
  puts if i%16==0
}

puts "#========== VARNAMES =================================#"
puts cdi.varnames.sort.join(" ")
puts cdi.varnames.grep(/max/).join(" <-> ")

puts "#========== VARIABLE.NAME =================================#"
puts cdi.variables.collect {|v| v.longname }.join("-")
puts cdi.variables.collect {|v| v.units }.join("-")

51
52
53
54
puts "#========== VAR by index ======================================#"
var = cdi.variables[1]
var.getValues()
val = var.values
55
pp val[-5..-1]
56
puts "#========= Var by name ===============================#"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
57
58
59
name ="tsurf"
newvar = cdi.var[name]
puts "name ",name," var.name: ", newvar.name, " var.grids.xsize: " , newvar.grid.xsize
60
61
62
63
puts "#========= Var by code ===============================#"
code = 169
newvar = cdi.varByCode[code]
newvar.sinfo