cdo 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/gemspec +3 -1
- data/lib/cdo.rb +18 -5
- data/test/test_cdo.rb +14 -23
- metadata +2 -2
data/gemspec
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
3
|
+
require 'cdo'
|
2
4
|
|
3
5
|
spec = Gem::Specification.new do |s|
|
4
6
|
s.name = "cdo"
|
5
|
-
s.version =
|
7
|
+
s.version = Cdo.version
|
6
8
|
s.platform = Gem::Platform::RUBY
|
7
9
|
s.files = ["lib/cdo.rb"] + ["gemspec","COPYING","README.rdoc","ChangeLog"]
|
8
10
|
s.test_file = "test/test_cdo.rb"
|
data/lib/cdo.rb
CHANGED
@@ -46,6 +46,8 @@ module Cdo
|
|
46
46
|
tstepcount vardes vardup varmul varquot2test varrms vertwind write_e5ml
|
47
47
|
writegrid writerandom yearcount]
|
48
48
|
|
49
|
+
@@outputOperatorsPattern = /(diff|info|output|griddes|zaxisdes|show)/
|
50
|
+
|
49
51
|
private
|
50
52
|
def Cdo.call(cmd)
|
51
53
|
if (State[:debug])
|
@@ -93,10 +95,11 @@ module Cdo
|
|
93
95
|
# iStream could be another CDO call (timmax(selname(Temp,U,V,ifile.nc))
|
94
96
|
puts "Operator #{sym.to_s} is called" if State[:debug]
|
95
97
|
if getOperators.include?(sym.to_s)
|
96
|
-
|
97
|
-
args.
|
98
|
-
|
99
|
-
|
98
|
+
opts = args.empty? ? '' : ',' + args.reject {|a| a.class == Hash}.join(',')
|
99
|
+
io = args.find {|a| a.class == Hash}
|
100
|
+
args.delete_if {|a| a.class == Hash}
|
101
|
+
if @@outputOperatorsPattern.match(sym)
|
102
|
+
run(" -#{sym.to_s}#{opts} #{io[:in]} ",$stdout)
|
100
103
|
else
|
101
104
|
opts = args.empty? ? '' : ',' + args.reject {|a| a.class == Hash}.join(',')
|
102
105
|
run(" -#{sym.to_s}#{opts} #{io[:in]} ",io[:out],io[:options],io[:returnArray])
|
@@ -122,6 +125,9 @@ module Cdo
|
|
122
125
|
def Cdo.debug
|
123
126
|
State[:debug]
|
124
127
|
end
|
128
|
+
def Cdo.version
|
129
|
+
"1.0.8"
|
130
|
+
end
|
125
131
|
def Cdo.setReturnArray(value=true)
|
126
132
|
if value
|
127
133
|
Cdo.loadCdf
|
@@ -135,9 +141,16 @@ module Cdo
|
|
135
141
|
State[:returnArray]
|
136
142
|
end
|
137
143
|
|
144
|
+
def Cdo.hasCdo?(bin=@@CDO)
|
145
|
+
return true if File.exists?(@@CDO) and File.executable?(@@CDO)
|
146
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each {|path|
|
147
|
+
return true if File.exists?([path,bin].join(File::SEPARATOR))
|
148
|
+
}
|
149
|
+
end
|
150
|
+
|
138
151
|
# test if @@CDO can be used
|
139
152
|
def Cdo.checkCdo
|
140
|
-
unless
|
153
|
+
unless hasCdo?(@@CDO)
|
141
154
|
warn "Testing application #@@CDO is not available!"
|
142
155
|
exit 1
|
143
156
|
else
|
data/test/test_cdo.rb
CHANGED
@@ -5,31 +5,15 @@ require 'pp'
|
|
5
5
|
|
6
6
|
class TestCdo < Test::Unit::TestCase
|
7
7
|
|
8
|
-
DEFAULT_CDO_PATH = '
|
9
|
-
def setup
|
10
|
-
if ENV['CDO'].nil?
|
11
|
-
if File.exists?(DEFAULT_CDO_PATH)
|
12
|
-
Cdo.setCdo(DEFAULT_CDO_PATH)
|
13
|
-
else
|
14
|
-
stop(DEFAULT_CDO_PATH)
|
15
|
-
end
|
16
|
-
else
|
17
|
-
# Check user given path
|
18
|
-
unless File.exists?(ENV['CDO'])
|
19
|
-
stop(ENV['CDO'])
|
20
|
-
else
|
21
|
-
Cdo.setCdo(ENV['CDO'])
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
def stop(path)
|
26
|
-
warn "Could not find CDO binary (#{path})! Abort tests"
|
27
|
-
exit
|
28
|
-
end
|
8
|
+
DEFAULT_CDO_PATH = 'cdo'
|
29
9
|
|
30
10
|
def test_cdo
|
31
11
|
assert_equal(true,Cdo.checkCdo)
|
32
|
-
|
12
|
+
if ENV['CDO']
|
13
|
+
assert_equal(ENV['CDO'],Cdo.getCdo)
|
14
|
+
else
|
15
|
+
assert_equal(DEFAULT_CDO_PATH,Cdo.getCdo)
|
16
|
+
end
|
33
17
|
newCDO="#{ENV['HOME']}/bin/cdo"
|
34
18
|
if File.exist?(newCDO) then
|
35
19
|
Cdo.setCdo(newCDO)
|
@@ -46,12 +30,19 @@ class TestCdo < Test::Unit::TestCase
|
|
46
30
|
end
|
47
31
|
}
|
48
32
|
end
|
49
|
-
def
|
33
|
+
def test_outputOperators
|
50
34
|
levels = Cdo.showlevel(:in => "-stdatm,0")
|
51
35
|
assert_equal([0,0].map(&:to_s),levels)
|
52
36
|
|
53
37
|
info = Cdo.sinfo(:in => "-stdatm,0")
|
54
38
|
assert_equal("File format: GRIB",info[0])
|
39
|
+
|
40
|
+
values = Cdo.outputkey("value",:in => "-stdatm,0")
|
41
|
+
assert_equal(["1013.25", "288"],values)
|
42
|
+
values = Cdo.outputkey("value",:in => "-stdatm,0,10000")
|
43
|
+
assert_equal(["1013.25", "271.913", "288", "240.591"],values)
|
44
|
+
values = Cdo.outputkey("level",:in => "-stdatm,0,10000")
|
45
|
+
assert_equal(["0", "10000","0", "10000"],values)
|
55
46
|
end
|
56
47
|
def test_args
|
57
48
|
#Cdo.Debug = true
|
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.8
|
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-04-11 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
|