cdo 1.0.9 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/gemspec +1 -2
- data/lib/cdo.rb +37 -18
- data/test/test_cdo.rb +30 -11
- metadata +2 -2
data/gemspec
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
$:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
3
|
-
require 'cdo'
|
4
3
|
|
5
4
|
spec = Gem::Specification.new do |s|
|
6
5
|
s.name = "cdo"
|
7
|
-
s.version = '1.0.
|
6
|
+
s.version = '1.0.10'
|
8
7
|
s.platform = Gem::Platform::RUBY
|
9
8
|
s.files = ["lib/cdo.rb"] + ["gemspec","COPYING","README.rdoc","ChangeLog"]
|
10
9
|
s.test_file = "test/test_cdo.rb"
|
data/lib/cdo.rb
CHANGED
@@ -15,11 +15,16 @@ require 'pp'
|
|
15
15
|
# ==============================================================================
|
16
16
|
# CDO calling mechnism
|
17
17
|
module Cdo
|
18
|
+
|
19
|
+
VERSION = "1.0.10"
|
20
|
+
|
18
21
|
State = {
|
19
22
|
:debug => false,
|
20
23
|
:returnArray => false,
|
21
24
|
:operators => []
|
22
25
|
}
|
26
|
+
State[:debug] = true unless ENV['DEBUG'].nil?
|
27
|
+
|
23
28
|
@@CDO = ENV['CDO'].nil? ? 'cdo' : ENV['CDO']
|
24
29
|
|
25
30
|
# Since cdo-1.5.4 undocumented operators are given with the -h option. For
|
@@ -31,7 +36,7 @@ module Cdo
|
|
31
36
|
ensrkhistspace ensrkhisttime eof3d eof3dspatial eof3dtime export_e5ml
|
32
37
|
export_e5res fc2gp fc2sp fillmiss fisher fldcovar fldrms fourier fpressure
|
33
38
|
gather gengrid geopotheight ggstat ggstats globavg gp2fc gradsdes
|
34
|
-
gridverify harmonic hourcount hpressure
|
39
|
+
gridverify harmonic hourcount hpressure import_e5ml import_e5res
|
35
40
|
import_obs imtocomplex infos infov interpolate intgrid intgridbil
|
36
41
|
intgridtraj intpoint isosurface lmavg lmean lmmean lmstd log lsmean
|
37
42
|
meandiff2test mergegrid mod moncount monlogs mrotuv mrotuvb mulcoslat ncode
|
@@ -49,6 +54,26 @@ module Cdo
|
|
49
54
|
@@outputOperatorsPattern = /(diff|info|output|griddes|zaxisdes|show)/
|
50
55
|
|
51
56
|
private
|
57
|
+
def Cdo.getOperators(force=false)
|
58
|
+
# Do NOT compute anything, if it is not required
|
59
|
+
return State[:operators] unless (State[:operators].empty? or force)
|
60
|
+
cmd = @@CDO + ' 2>&1'
|
61
|
+
help = IO.popen(cmd).readlines.map {|l| l.chomp.lstrip}
|
62
|
+
if 5 >= help.size
|
63
|
+
warn "Operators could not get listed by running the CDO binary (#{@@CDO})"
|
64
|
+
pp help if Cdo.debug
|
65
|
+
exit
|
66
|
+
end
|
67
|
+
# in version 1.5.6 the output of '-h' has changed
|
68
|
+
State[:operators] = case
|
69
|
+
when Cdo.version < "1.5.6"
|
70
|
+
(help[help.index("Operators:")+1].split + @@undocumentedOperators).uniq
|
71
|
+
else
|
72
|
+
help[(help.index("Operators:")+1)..help.index(help.find {|v| v =~ /CDO version/}) - 2].join(' ').split
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
end
|
52
77
|
def Cdo.call(cmd)
|
53
78
|
if (State[:debug])
|
54
79
|
puts '# DEBUG ====================================================================='
|
@@ -59,14 +84,14 @@ module Cdo
|
|
59
84
|
system(cmd + ' 1>/dev/null 2>&1 ')
|
60
85
|
end
|
61
86
|
end
|
62
|
-
def Cdo.run(cmd,ofile=
|
87
|
+
def Cdo.run(cmd,ofile='',options='',returnArray=false)
|
63
88
|
cmd = "#{@@CDO} -O #{options} #{cmd} "
|
64
89
|
case ofile
|
65
90
|
when $stdout
|
66
91
|
cmd << " 2>/dev/null"
|
67
92
|
return IO.popen(cmd).readlines.map {|l| l.chomp.strip}
|
68
93
|
when nil
|
69
|
-
ofile =
|
94
|
+
ofile = MyTempfile.path
|
70
95
|
end
|
71
96
|
cmd << "#{ofile}"
|
72
97
|
call(cmd)
|
@@ -76,26 +101,15 @@ module Cdo
|
|
76
101
|
return ofile
|
77
102
|
end
|
78
103
|
end
|
79
|
-
def Cdo.getOperators(force=false)
|
80
|
-
# Do NOT compute anything, if it is not required
|
81
|
-
return State[:operators] unless (State[:operators].empty? or force)
|
82
|
-
|
83
|
-
cmd = @@CDO + ' 2>&1'
|
84
|
-
help = IO.popen(cmd).readlines.map {|l| l.chomp.lstrip}
|
85
|
-
if 5 >= help.size
|
86
|
-
warn "Operators could not get listed by running the CDO binary (#{@@CDO})"
|
87
|
-
pp help if Cdo.debug
|
88
|
-
exit
|
89
|
-
end
|
90
|
-
State[:operators] = (help[help.index("Operators:")+1].split + @@undocumentedOperators).uniq
|
91
|
-
end
|
92
104
|
def Cdo.method_missing(sym, *args, &block)
|
93
105
|
# args is expected to look like [opt1,...,optN,:in => iStream,:out => oStream] where
|
94
106
|
# iStream could be another CDO call (timmax(selname(Temp,U,V,ifile.nc))
|
95
107
|
puts "Operator #{sym.to_s} is called" if State[:debug]
|
96
108
|
if getOperators.include?(sym.to_s)
|
97
|
-
|
109
|
+
operatorArgs = args.reject {|a| a.class == Hash}
|
110
|
+
opts = operatorArgs.empty? ? '' : ',' + operatorArgs.join(',')
|
98
111
|
io = args.find {|a| a.class == Hash}
|
112
|
+
io = {} if io.nil?
|
99
113
|
args.delete_if {|a| a.class == Hash}
|
100
114
|
if @@outputOperatorsPattern.match(sym)
|
101
115
|
run(" -#{sym.to_s}#{opts} #{io[:in]} ",$stdout)
|
@@ -125,7 +139,11 @@ module Cdo
|
|
125
139
|
State[:debug]
|
126
140
|
end
|
127
141
|
def Cdo.version
|
128
|
-
|
142
|
+
cmd = @@CDO + ' 2>&1'
|
143
|
+
help = IO.popen(cmd).readlines.map {|l| l.chomp.lstrip}
|
144
|
+
regexp = %r{CDO version (\d.*), Copyright}
|
145
|
+
line = help.find {|v| v =~ regexp}
|
146
|
+
version = regexp.match(line)[1]
|
129
147
|
end
|
130
148
|
def Cdo.setReturnArray(value=true)
|
131
149
|
if value
|
@@ -167,6 +185,7 @@ module Cdo
|
|
167
185
|
@@CDO
|
168
186
|
end
|
169
187
|
def Cdo.operators
|
188
|
+
Cdo.getOperators if State[:operators].empty?
|
170
189
|
State[:operators]
|
171
190
|
end
|
172
191
|
|
data/test/test_cdo.rb
CHANGED
@@ -26,10 +26,14 @@ class TestCdo < Test::Unit::TestCase
|
|
26
26
|
if ["thicknessOfLevels"].include?(op)
|
27
27
|
assert(Cdo.respond_to?(op),"Operator '#{op}' not found")
|
28
28
|
else
|
29
|
-
assert(Cdo.getOperators.include?(op))
|
29
|
+
assert(Cdo.getOperators.include?(op),"Operator '#{op}' not found")
|
30
30
|
end
|
31
31
|
}
|
32
32
|
end
|
33
|
+
def test_listAllOperators
|
34
|
+
print Cdo.operators.join("\n")
|
35
|
+
end
|
36
|
+
|
33
37
|
def test_outputOperators
|
34
38
|
levels = Cdo.showlevel(:in => "-stdatm,0")
|
35
39
|
assert_equal([0,0].map(&:to_s),levels)
|
@@ -44,6 +48,9 @@ class TestCdo < Test::Unit::TestCase
|
|
44
48
|
values = Cdo.outputkey("level",:in => "-stdatm,0,10000")
|
45
49
|
assert_equal(["0", "10000","0", "10000"],values)
|
46
50
|
end
|
51
|
+
def test_CDO_version
|
52
|
+
assert("1.4.3.1" < Cdo.version,"Version to low: #{Cdo.version}")
|
53
|
+
end
|
47
54
|
def test_args
|
48
55
|
#Cdo.Debug = true
|
49
56
|
#MyTempfile.setPersist(true)
|
@@ -88,6 +95,11 @@ class TestCdo < Test::Unit::TestCase
|
|
88
95
|
assert_equal(diff[1].split(' ')[-1],"0.53060")
|
89
96
|
end
|
90
97
|
|
98
|
+
def test_operators
|
99
|
+
assert_includes(Cdo.operators,"infov")
|
100
|
+
assert_includes(Cdo.operators,"showlevel")
|
101
|
+
end
|
102
|
+
|
91
103
|
def test_bndLevels
|
92
104
|
ofile = MyTempfile.path
|
93
105
|
Cdo.stdatm(25,100,250,500,875,1400,2100,3000,4000,5000,:out => ofile,:options => "-f nc")
|
@@ -112,6 +124,11 @@ class TestCdo < Test::Unit::TestCase
|
|
112
124
|
def test_tempfile
|
113
125
|
ofile0, ofile1 = MyTempfile.path, MyTempfile.path
|
114
126
|
assert_not_equal(ofile0,ofile1)
|
127
|
+
# Tempfile should not disappeare even if the GC was started
|
128
|
+
puts ofile0
|
129
|
+
assert(File.exist?(ofile0))
|
130
|
+
GC.start
|
131
|
+
assert(File.exist?(ofile0))
|
115
132
|
end
|
116
133
|
|
117
134
|
def test_returnArray
|
@@ -143,17 +160,19 @@ class TestCdo < Test::Unit::TestCase
|
|
143
160
|
assert_equal(targetThicknesses, Cdo.thicknessOfLevels(:in => "-selname,T -stdatm,#{levels.join(',')}"))
|
144
161
|
end
|
145
162
|
|
163
|
+
def test_showlevels
|
164
|
+
sourceLevels = %W{25 100 250 500 875 1400 2100 3000 4000 5000}
|
165
|
+
assert_equal(sourceLevels,
|
166
|
+
Cdo.showlevel(:in => "-selname,T #{Cdo.stdatm(*sourceLevels,:options => '-f nc')}")[0].split)
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_verticalLevels
|
170
|
+
targetThicknesses = [50.0, 100.0, 200.0, 300.0, 450.0, 600.0, 800.0, 1000.0, 1000.0, 1000.0]
|
171
|
+
sourceLevels = %W{25 100 250 500 875 1400 2100 3000 4000 5000}
|
172
|
+
thicknesses = Cdo.thicknessOfLevels(:in => "-selname,T #{Cdo.stdatm(*sourceLevels,:options => '-f nc')}")
|
173
|
+
assert_equal(targetThicknesses,thicknesses)
|
174
|
+
end
|
146
175
|
if 'thingol' == `hostname`.chomp then
|
147
|
-
def test_verticalLevels
|
148
|
-
iconpath = "/home/ram/src/git/icon/grids"
|
149
|
-
# check, if a given input files has vertival layers of a given thickness array
|
150
|
-
targetThicknesses = [50.0, 100.0, 200.0, 300.0, 450.0, 600.0, 800.0, 1000.0, 1000.0, 1000.0]
|
151
|
-
ifile = [iconpath,"ts_phc_annual-iconR2B04-L10_50-1000m.nc"].join('/')
|
152
|
-
assert_equal(["25 100 250 500 875 1400 2100 3000 4000 5000",
|
153
|
-
"25 100 250 500 875 1400 2100 3000 4000 5000"],Cdo.showlevel(:in => ifile))
|
154
|
-
thicknesses = Cdo.thicknessOfLevels(:in => ifile)
|
155
|
-
assert_equal(targetThicknesses,thicknesses)
|
156
|
-
end
|
157
176
|
def test_readCdf
|
158
177
|
input = "-settunits,days -setyear,2000 -for,1,4"
|
159
178
|
cdfFile = Cdo.copy(:options =>"-f nc",:in=>input)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cdo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-03 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Easy access to the Climate Data operators
|
15
15
|
email: stark.dreamdetective@gmail.com
|