cdo 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/gemspec +2 -2
- data/lib/cdo.rb +40 -31
- data/test/test_cdo.rb +19 -3
- metadata +4 -4
data/gemspec
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
spec = Gem::Specification.new do |s|
|
4
4
|
s.name = "cdo"
|
5
|
-
s.version = '1.0.
|
5
|
+
s.version = '1.0.7'
|
6
6
|
s.platform = Gem::Platform::RUBY
|
7
7
|
s.files = ["lib/cdo.rb"] + ["gemspec","COPYING","README.rdoc","ChangeLog"]
|
8
8
|
s.test_file = "test/test_cdo.rb"
|
@@ -10,7 +10,7 @@ spec = Gem::Specification.new do |s|
|
|
10
10
|
s.summary = "Easy access to the Climate Data operators"
|
11
11
|
s.author = "Ralf Mueller"
|
12
12
|
s.email = "stark.dreamdetective@gmail.com"
|
13
|
-
s.homepage = "
|
13
|
+
s.homepage = "https://code.zmaw.de/projects/cdo/wiki/Cdo%7Brbpy%7D"
|
14
14
|
s.extra_rdoc_files = ["README.rdoc","COPYING"]
|
15
15
|
s.license = "GPLv2"
|
16
16
|
s.required_ruby_version = ">= 1.9"
|
data/lib/cdo.rb
CHANGED
@@ -20,7 +20,7 @@ module Cdo
|
|
20
20
|
:returnArray => false,
|
21
21
|
:operators => []
|
22
22
|
}
|
23
|
-
@@CDO = ENV['CDO'].nil? ? '
|
23
|
+
@@CDO = ENV['CDO'].nil? ? 'cdo' : ENV['CDO']
|
24
24
|
|
25
25
|
# Since cdo-1.5.4 undocumented operators are given with the -h option. For
|
26
26
|
# earlier version, they have to be provided manually
|
@@ -75,6 +75,36 @@ module Cdo
|
|
75
75
|
return ofile
|
76
76
|
end
|
77
77
|
end
|
78
|
+
def Cdo.getOperators(force=false)
|
79
|
+
# Do NOT compute anything, if it is not required
|
80
|
+
return State[:operators] unless (State[:operators].empty? or force)
|
81
|
+
|
82
|
+
cmd = @@CDO + ' 2>&1'
|
83
|
+
help = IO.popen(cmd).readlines.map {|l| l.chomp.lstrip}
|
84
|
+
if 5 >= help.size
|
85
|
+
warn "Operators could not get listed by running the CDO binary (#{@@CDO})"
|
86
|
+
pp help if Cdo.debug
|
87
|
+
exit
|
88
|
+
end
|
89
|
+
State[:operators] = (help[help.index("Operators:")+1].split + @@undocumentedOperators).uniq
|
90
|
+
end
|
91
|
+
def Cdo.method_missing(sym, *args, &block)
|
92
|
+
# args is expected to look like [opt1,...,optN,:in => iStream,:out => oStream] where
|
93
|
+
# iStream could be another CDO call (timmax(selname(Temp,U,V,ifile.nc))
|
94
|
+
puts "Operator #{sym.to_s} is called" if State[:debug]
|
95
|
+
if getOperators.include?(sym.to_s)
|
96
|
+
io = args.find {|a| a.class == Hash}
|
97
|
+
args.delete_if {|a| a.class == Hash}
|
98
|
+
if /(diff|info|show|griddes)/.match(sym)
|
99
|
+
run(" -#{sym.to_s} #{io[:in]} ",$stdout)
|
100
|
+
else
|
101
|
+
opts = args.empty? ? '' : ',' + args.reject {|a| a.class == Hash}.join(',')
|
102
|
+
run(" -#{sym.to_s}#{opts} #{io[:in]} ",io[:out],io[:options],io[:returnArray])
|
103
|
+
end
|
104
|
+
else
|
105
|
+
warn "Operator #{sym.to_s} not found"
|
106
|
+
end
|
107
|
+
end
|
78
108
|
def Cdo.loadCdf
|
79
109
|
begin
|
80
110
|
require "numru/netcdf"
|
@@ -114,43 +144,18 @@ module Cdo
|
|
114
144
|
puts "Using CDO: #@@CDO"
|
115
145
|
puts IO.popen(@@CDO + " -V").readlines
|
116
146
|
end
|
147
|
+
return true
|
117
148
|
end
|
118
149
|
def Cdo.setCdo(cdo)
|
119
150
|
puts "Will use #{cdo} instead of #@@CDO" if Cdo.debug
|
120
151
|
@@CDO = cdo
|
121
152
|
Cdo.getOperators(true)
|
122
153
|
end
|
123
|
-
|
124
|
-
|
125
|
-
# Do NOT compute anything, if it is not required
|
126
|
-
return State[:operators] unless (State[:operators].empty? or force)
|
127
|
-
|
128
|
-
cmd = @@CDO + ' 2>&1'
|
129
|
-
help = IO.popen(cmd).readlines.map {|l| l.chomp.lstrip}
|
130
|
-
if 5 >= help.size
|
131
|
-
warn "Operators could not get listed by running the CDO binary (#{@@CDO})"
|
132
|
-
pp help if Cdo.debug
|
133
|
-
exit
|
134
|
-
end
|
135
|
-
State[:operators] = (help[help.index("Operators:")+1].split + @@undocumentedOperators).uniq
|
154
|
+
def Cdo.getCdo
|
155
|
+
@@CDO
|
136
156
|
end
|
137
|
-
|
138
|
-
|
139
|
-
# args is expected to look like [opt1,...,optN,:in => iStream,:out => oStream] where
|
140
|
-
# iStream could be another CDO call (timmax(selname(Temp,U,V,ifile.nc))
|
141
|
-
puts "Operator #{sym.to_s} is called" if State[:debug]
|
142
|
-
if getOperators.include?(sym.to_s)
|
143
|
-
io = args.find {|a| a.class == Hash}
|
144
|
-
args.delete_if {|a| a.class == Hash}
|
145
|
-
if /(diff|info|show|griddes)/.match(sym)
|
146
|
-
run(" -#{sym.to_s} #{io[:in]} ",$stdout)
|
147
|
-
else
|
148
|
-
opts = args.empty? ? '' : ',' + args.reject {|a| a.class == Hash}.join(',')
|
149
|
-
run(" -#{sym.to_s}#{opts} #{io[:in]} ",io[:out],io[:options],io[:returnArray])
|
150
|
-
end
|
151
|
-
else
|
152
|
-
warn "Operator #{sym.to_s} not found"
|
153
|
-
end
|
157
|
+
def Cdo.operators
|
158
|
+
State[:operators]
|
154
159
|
end
|
155
160
|
|
156
161
|
#==================================================================
|
@@ -195,6 +200,7 @@ module MyTempfile
|
|
195
200
|
unless @@persistent_tempfiles
|
196
201
|
t = Tempfile.new(self.class.to_s)
|
197
202
|
@@_tempfiles << t
|
203
|
+
@@_tempfiles << t.path
|
198
204
|
t.path
|
199
205
|
else
|
200
206
|
t = "_"+rand(@@N).to_s
|
@@ -202,4 +208,7 @@ module MyTempfile
|
|
202
208
|
t
|
203
209
|
end
|
204
210
|
end
|
211
|
+
def MyTempfile.showFiles
|
212
|
+
@@_tempfiles.each {|f| print(f+" ") if f.kind_of? String}
|
213
|
+
end
|
205
214
|
end
|
data/test/test_cdo.rb
CHANGED
@@ -27,6 +27,16 @@ class TestCdo < Test::Unit::TestCase
|
|
27
27
|
exit
|
28
28
|
end
|
29
29
|
|
30
|
+
def test_cdo
|
31
|
+
assert_equal(true,Cdo.checkCdo)
|
32
|
+
assert_equal('/usr/bin/cdo',Cdo.getCdo)
|
33
|
+
newCDO="#{ENV['HOME']}/bin/cdo"
|
34
|
+
if File.exist?(newCDO) then
|
35
|
+
Cdo.setCdo(newCDO)
|
36
|
+
assert_equal(true,Cdo.checkCdo)
|
37
|
+
assert_equal(newCDO,Cdo.getCdo)
|
38
|
+
end
|
39
|
+
end
|
30
40
|
def test_getOperators
|
31
41
|
%w[for random stdatm info showlevel sinfo remap geopotheight mask topo thicknessOfLevels].each {|op|
|
32
42
|
if ["thicknessOfLevels"].include?(op)
|
@@ -99,14 +109,20 @@ class TestCdo < Test::Unit::TestCase
|
|
99
109
|
def test_combine
|
100
110
|
ofile0, ofile1 = MyTempfile.path, MyTempfile.path
|
101
111
|
Cdo.fldsum(:in => Cdo.stdatm(25,100,250,500,875,1400,2100,3000,4000,5000,:options => "-f nc"),:out => ofile0)
|
102
|
-
|
103
|
-
Cdo.setReturnArray
|
104
|
-
|
112
|
+
Cdo.fldsum(:in => "-stdatm,25,100,250,500,875,1400,2100,3000,4000,5000",:options => "-f nc",:out => ofile1)
|
113
|
+
Cdo.setReturnArray
|
114
|
+
MyTempfile.showFiles
|
115
|
+
diff = Cdo.sub(:in => [ofile0,ofile1].join(' ')).var('T').get
|
105
116
|
assert_equal(0.0,diff.min)
|
106
117
|
assert_equal(0.0,diff.max)
|
107
118
|
Cdo.setReturnArray(false)
|
108
119
|
end
|
109
120
|
|
121
|
+
def test_tempfile
|
122
|
+
ofile0, ofile1 = MyTempfile.path, MyTempfile.path
|
123
|
+
assert_not_equal(ofile0,ofile1)
|
124
|
+
end
|
125
|
+
|
110
126
|
def test_returnArray
|
111
127
|
ofile = MyTempfile.path
|
112
128
|
vals = Cdo.stdatm(25,100,250,500,875,1400,2100,3000,4000,5000,:out => ofile,:options => "-f nc")
|
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.7
|
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-03-22 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
|
@@ -25,7 +25,7 @@ files:
|
|
25
25
|
- README.rdoc
|
26
26
|
- ChangeLog
|
27
27
|
- test/test_cdo.rb
|
28
|
-
homepage:
|
28
|
+
homepage: https://code.zmaw.de/projects/cdo/wiki/Cdo%7Brbpy%7D
|
29
29
|
licenses:
|
30
30
|
- GPLv2
|
31
31
|
post_install_message:
|
@@ -46,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
46
|
version: '0'
|
47
47
|
requirements: []
|
48
48
|
rubyforge_project:
|
49
|
-
rubygems_version: 1.8.
|
49
|
+
rubygems_version: 1.8.17
|
50
50
|
signing_key:
|
51
51
|
specification_version: 3
|
52
52
|
summary: Easy access to the Climate Data operators
|