cdo 1.1.0 → 1.2.0
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/README.rdoc +5 -5
- data/gemspec +1 -1
- data/lib/cdo.rb +24 -11
- data/test/test_cdo.rb +76 -61
- metadata +2 -2
data/README.rdoc
CHANGED
|
@@ -24,20 +24,20 @@ Cdo.rb requires a working CDO binary, but has not special requirement to Ruby
|
|
|
24
24
|
|
|
25
25
|
* File information
|
|
26
26
|
|
|
27
|
-
Cdo.infov(:
|
|
28
|
-
Cdo.showlevels(:
|
|
27
|
+
Cdo.infov(:input => ifile)
|
|
28
|
+
Cdo.showlevels(:input => ifile)
|
|
29
29
|
|
|
30
30
|
* Operators with regular output files
|
|
31
31
|
|
|
32
|
-
Cdo.timmin(:
|
|
32
|
+
Cdo.timmin(:input => ifile,:output => ofile)
|
|
33
33
|
|
|
34
34
|
* Operators with options
|
|
35
35
|
|
|
36
|
-
Cdo.remap([gridfile,weightfile],:
|
|
36
|
+
Cdo.remap([gridfile,weightfile],:input => ifile, :output => ofile)
|
|
37
37
|
|
|
38
38
|
* Set global CDO options
|
|
39
39
|
|
|
40
|
-
Cdo.copy(:
|
|
40
|
+
Cdo.copy(:input => ifile, :output => ofile,:options => "-f nc4")
|
|
41
41
|
|
|
42
42
|
More examples can be found in test/cdo-examples.rb.
|
|
43
43
|
|
data/gemspec
CHANGED
|
@@ -3,7 +3,7 @@ $:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
|
|
3
3
|
|
|
4
4
|
spec = Gem::Specification.new do |s|
|
|
5
5
|
s.name = "cdo"
|
|
6
|
-
s.version = '1.
|
|
6
|
+
s.version = '1.2.0'
|
|
7
7
|
s.platform = Gem::Platform::RUBY
|
|
8
8
|
s.files = ["lib/cdo.rb"] + ["gemspec","COPYING","README.rdoc","ChangeLog"]
|
|
9
9
|
s.test_file = "test/test_cdo.rb"
|
data/lib/cdo.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'pp'
|
|
2
|
+
require 'open3'
|
|
2
3
|
|
|
3
4
|
# Copyright (C) 2011-2012 Ralf Mueller, ralf.mueller@zmaw.de
|
|
4
5
|
# See COPYING file for copying and redistribution conditions.
|
|
@@ -16,7 +17,7 @@ require 'pp'
|
|
|
16
17
|
# CDO calling mechnism
|
|
17
18
|
module Cdo
|
|
18
19
|
|
|
19
|
-
VERSION = "1.
|
|
20
|
+
VERSION = "1.2.0"
|
|
20
21
|
|
|
21
22
|
State = {
|
|
22
23
|
:debug => false,
|
|
@@ -89,9 +90,10 @@ module Cdo
|
|
|
89
90
|
cmd = "#{@@CDO} -O #{options} #{cmd} "
|
|
90
91
|
case ofile
|
|
91
92
|
when $stdout
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
stdin, stdout, stderr, status = Open3.popen3(cmd)
|
|
94
|
+
retval = stdout.read.split($/).map {|l| l.chomp.strip}
|
|
95
|
+
pp stderr.read
|
|
96
|
+
return retval
|
|
95
97
|
else
|
|
96
98
|
force = State[:forceOutput] if force.nil?
|
|
97
99
|
if force or not File.exists?(ofile.to_s)
|
|
@@ -102,7 +104,9 @@ module Cdo
|
|
|
102
104
|
warn "Use existing file '#{ofile}'" if Cdo.debug
|
|
103
105
|
end
|
|
104
106
|
end
|
|
105
|
-
if
|
|
107
|
+
if not returnArray.nil?
|
|
108
|
+
Cdo.readArray(ofile,returnArray)
|
|
109
|
+
elsif returnCdf or State[:returnCdf]
|
|
106
110
|
Cdo.readCdf(ofile)
|
|
107
111
|
else
|
|
108
112
|
return ofile
|
|
@@ -118,17 +122,15 @@ module Cdo
|
|
|
118
122
|
return [io,opts]
|
|
119
123
|
end
|
|
120
124
|
def Cdo.method_missing(sym, *args, &block)
|
|
121
|
-
## args is expected to look like [opt1,...,optN,:
|
|
125
|
+
## args is expected to look like [opt1,...,optN,:input => iStream,:output => oStream] where
|
|
122
126
|
# iStream could be another CDO call (timmax(selname(Temp,U,V,ifile.nc))
|
|
123
127
|
puts "Operator #{sym.to_s} is called" if State[:debug]
|
|
124
128
|
if getOperators.include?(sym.to_s)
|
|
125
129
|
io,opts = Cdo.parseArgs(args)
|
|
126
130
|
if @@outputOperatorsPattern.match(sym)
|
|
127
|
-
run(" -#{sym.to_s}#{opts} #{io[:
|
|
131
|
+
run(" -#{sym.to_s}#{opts} #{io[:input]} ",$stdout)
|
|
128
132
|
else
|
|
129
|
-
#
|
|
130
|
-
run(" -#{sym.to_s}#{opts} #{io[:in]} ",io[:out],io[:options],io[:returnCdf],io[:force])
|
|
131
|
-
#end
|
|
133
|
+
run(" -#{sym.to_s}#{opts} #{io[:input]} ",io[:output],io[:options],io[:returnCdf],io[:force],io[:returnArray])
|
|
132
134
|
end
|
|
133
135
|
else
|
|
134
136
|
warn "Operator #{sym.to_s} not found"
|
|
@@ -212,7 +214,7 @@ module Cdo
|
|
|
212
214
|
# Addional operotors:
|
|
213
215
|
#------------------------------------------------------------------
|
|
214
216
|
def Cdo.boundaryLevels(args)
|
|
215
|
-
ilevels = Cdo.showlevel(:
|
|
217
|
+
ilevels = Cdo.showlevel(:input => args[:input])[0].split.map(&:to_f)
|
|
216
218
|
bound_levels = Array.new(ilevels.size+1)
|
|
217
219
|
bound_levels[0] = 0
|
|
218
220
|
(1..ilevels.size).each {|i|
|
|
@@ -236,6 +238,17 @@ module Cdo
|
|
|
236
238
|
NetCDF.open(iFile)
|
|
237
239
|
end
|
|
238
240
|
|
|
241
|
+
def Cdo.readArray(iFile,varname)
|
|
242
|
+
filehandle = Cdo.readCdf(iFile)
|
|
243
|
+
if filehandle.var_names.include?(varname)
|
|
244
|
+
# return the data array
|
|
245
|
+
filehandle.var(varname).get
|
|
246
|
+
else
|
|
247
|
+
warn "Cannot find variable '#{varname}'"
|
|
248
|
+
raise ArgumentError
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
|
|
239
252
|
def Cdo.selindexlist(args)
|
|
240
253
|
|
|
241
254
|
end
|
data/test/test_cdo.rb
CHANGED
|
@@ -36,17 +36,17 @@ class TestCdo < Test::Unit::TestCase
|
|
|
36
36
|
|
|
37
37
|
def test_outputOperators
|
|
38
38
|
Cdo.debug = true
|
|
39
|
-
levels = Cdo.showlevel(:
|
|
39
|
+
levels = Cdo.showlevel(:input => "-stdatm,0")
|
|
40
40
|
assert_equal([0,0].map(&:to_s),levels)
|
|
41
41
|
|
|
42
|
-
info = Cdo.sinfo(:
|
|
42
|
+
info = Cdo.sinfo(:input => "-stdatm,0")
|
|
43
43
|
assert_equal("File format: GRIB",info[0])
|
|
44
44
|
|
|
45
|
-
values = Cdo.outputkey("value",:
|
|
45
|
+
values = Cdo.outputkey("value",:input => "-stdatm,0")
|
|
46
46
|
assert_equal(["1013.25", "288"],values)
|
|
47
|
-
values = Cdo.outputkey("value",:
|
|
47
|
+
values = Cdo.outputkey("value",:input => "-stdatm,0,10000")
|
|
48
48
|
assert_equal(["1013.25", "271.913", "288", "240.591"],values)
|
|
49
|
-
values = Cdo.outputkey("level",:
|
|
49
|
+
values = Cdo.outputkey("level",:input => "-stdatm,0,10000")
|
|
50
50
|
assert_equal(["0", "10000","0", "10000"],values)
|
|
51
51
|
end
|
|
52
52
|
def test_CDO_version
|
|
@@ -59,39 +59,38 @@ class TestCdo < Test::Unit::TestCase
|
|
|
59
59
|
ofile1 = MyTempfile.path
|
|
60
60
|
ofile2 = MyTempfile.path
|
|
61
61
|
ofile3 = MyTempfile.path
|
|
62
|
-
Cdo.stdatm(0,20,40,80,200,230,400,600,1100,:
|
|
63
|
-
Cdo.intlevel(0,10,50,100,500,1000, :
|
|
64
|
-
Cdo.intlevel([0,10,50,100,500,1000],:
|
|
65
|
-
Cdo.sub(:
|
|
66
|
-
info = Cdo.infon(:
|
|
62
|
+
Cdo.stdatm(0,20,40,80,200,230,400,600,1100,:output => ofile0)
|
|
63
|
+
Cdo.intlevel(0,10,50,100,500,1000, :input => ofile0,:output => ofile1)
|
|
64
|
+
Cdo.intlevel([0,10,50,100,500,1000],:input => ofile0,:output => ofile2)
|
|
65
|
+
Cdo.sub(:input => [ofile1,ofile2].join(' '),:output => ofile3)
|
|
66
|
+
info = Cdo.infon(:input => ofile3)
|
|
67
67
|
(1...info.size).each {|i| assert_equal(0.0,info[i].split[-1].to_f)}
|
|
68
68
|
end
|
|
69
69
|
def test_operator_options
|
|
70
70
|
targetLevels = [0,10,50,100,200,400,1000]
|
|
71
71
|
ofile = Cdo.stdatm(targetLevels)
|
|
72
|
-
levels = Cdo.showlevel(:
|
|
72
|
+
levels = Cdo.showlevel(:input => ofile)
|
|
73
73
|
[0,1].each {|i| assert_equal(targetLevels.map(&:to_s),levels[i].split)}
|
|
74
74
|
end
|
|
75
75
|
def test_CDO_options
|
|
76
|
-
names = Cdo.showname(:
|
|
76
|
+
names = Cdo.showname(:input => "-stdatm,0",:options => "-f nc")
|
|
77
77
|
assert_equal(["P T"],names)
|
|
78
78
|
|
|
79
|
-
ofile =
|
|
80
|
-
Cdo.
|
|
81
|
-
assert_equal(["GRIB SZIP"],Cdo.showformat(:in => ofile))
|
|
79
|
+
ofile = Cdo.topo(:output => ofile,:options => "-z szip")
|
|
80
|
+
assert_equal(["GRIB SZIP"],Cdo.showformat(:input => ofile))
|
|
82
81
|
end
|
|
83
82
|
def test_chain
|
|
84
|
-
|
|
85
|
-
Cdo.
|
|
86
|
-
|
|
87
|
-
assert_equal(["veloc"],Cdo.showname(:in => ofile))
|
|
83
|
+
Cdo.debug = true
|
|
84
|
+
ofile = Cdo.setname('veloc',:input => " -copy -random,r1x1",:options => "-f nc")
|
|
85
|
+
assert_equal(["veloc"],Cdo.showname(:input => ofile))
|
|
88
86
|
end
|
|
89
87
|
|
|
90
88
|
def test_diff
|
|
91
|
-
|
|
89
|
+
Cdo.debug = true
|
|
90
|
+
diffv = Cdo.diffn(:input => "-random,r1x1 -random,r1x1")
|
|
92
91
|
assert_equal(diffv[1].split(' ')[-1],"random")
|
|
93
92
|
assert_equal(diffv[1].split(' ')[-3],"0.53060")
|
|
94
|
-
diff = Cdo.diff(:
|
|
93
|
+
diff = Cdo.diff(:input => "-random,r1x1 -random,r1x1")
|
|
95
94
|
assert_equal(diff[1].split(' ')[-3],"0.53060")
|
|
96
95
|
end
|
|
97
96
|
|
|
@@ -101,21 +100,20 @@ class TestCdo < Test::Unit::TestCase
|
|
|
101
100
|
end
|
|
102
101
|
|
|
103
102
|
def test_bndLevels
|
|
104
|
-
ofile =
|
|
105
|
-
Cdo.stdatm(25,100,250,500,875,1400,2100,3000,4000,5000,:out => ofile,:options => "-f nc")
|
|
103
|
+
ofile = Cdo.stdatm(25,100,250,500,875,1400,2100,3000,4000,5000,:options => "-f nc")
|
|
106
104
|
assert_equal([0, 50.0, 150.0, 350.0, 650.0, 1100.0, 1700.0, 2500.0, 3500.0, 4500.0, 5500.0],
|
|
107
|
-
Cdo.boundaryLevels(:
|
|
105
|
+
Cdo.boundaryLevels(:input => "-selname,T #{ofile}"))
|
|
108
106
|
assert_equal([50.0, 100.0, 200.0, 300.0, 450.0, 600.0, 800.0, 1000.0, 1000.0, 1000.0],
|
|
109
|
-
Cdo.thicknessOfLevels(:
|
|
107
|
+
Cdo.thicknessOfLevels(:input => ofile))
|
|
110
108
|
end
|
|
111
109
|
|
|
112
110
|
def test_combine
|
|
113
111
|
ofile0, ofile1 = MyTempfile.path, MyTempfile.path
|
|
114
|
-
Cdo.fldsum(:
|
|
115
|
-
Cdo.fldsum(:
|
|
112
|
+
Cdo.fldsum(:input => Cdo.stdatm(25,100,250,500,875,1400,2100,3000,4000,5000,:options => "-f nc"),:output => ofile0)
|
|
113
|
+
Cdo.fldsum(:input => "-stdatm,25,100,250,500,875,1400,2100,3000,4000,5000",:options => "-f nc",:output => ofile1)
|
|
116
114
|
Cdo.setReturnCdf
|
|
117
115
|
MyTempfile.showFiles
|
|
118
|
-
diff = Cdo.sub(:
|
|
116
|
+
diff = Cdo.sub(:input => [ofile0,ofile1].join(' ')).var('T').get
|
|
119
117
|
assert_equal(0.0,diff.min)
|
|
120
118
|
assert_equal(0.0,diff.max)
|
|
121
119
|
Cdo.setReturnCdf(false)
|
|
@@ -132,23 +130,24 @@ class TestCdo < Test::Unit::TestCase
|
|
|
132
130
|
end
|
|
133
131
|
|
|
134
132
|
def test_returnCdf
|
|
135
|
-
ofile =
|
|
136
|
-
vals = Cdo.stdatm(25,100,250,500,875,1400,2100,3000,4000,5000,:
|
|
133
|
+
ofile = rand(0xfffff).to_s + '_test_returnCdf.nc'
|
|
134
|
+
vals = Cdo.stdatm(25,100,250,500,875,1400,2100,3000,4000,5000,:output => ofile,:options => "-f nc")
|
|
137
135
|
assert_equal(ofile,vals)
|
|
138
136
|
Cdo.setReturnCdf
|
|
139
|
-
vals = Cdo.stdatm(25,100,250,500,875,1400,2100,3000,4000,5000,:
|
|
137
|
+
vals = Cdo.stdatm(25,100,250,500,875,1400,2100,3000,4000,5000,:output => ofile,:options => "-f nc")
|
|
140
138
|
assert_equal(["lon","lat","level","P","T"],vals.var_names)
|
|
141
139
|
assert_equal(276,vals.var("T").get.flatten.mean.floor)
|
|
142
140
|
Cdo.unsetReturnCdf
|
|
143
|
-
vals = Cdo.stdatm(25,100,250,500,875,1400,2100,3000,4000,5000,:
|
|
141
|
+
vals = Cdo.stdatm(25,100,250,500,875,1400,2100,3000,4000,5000,:output => ofile,:options => "-f nc")
|
|
144
142
|
assert_equal(ofile,vals)
|
|
143
|
+
FileUtils.rm(ofile)
|
|
145
144
|
end
|
|
146
145
|
def test_simple_returnCdf
|
|
147
146
|
ofile0, ofile1 = MyTempfile.path, MyTempfile.path
|
|
148
|
-
sum = Cdo.fldsum(:
|
|
147
|
+
sum = Cdo.fldsum(:input => Cdo.stdatm(0,:options => "-f nc"),
|
|
149
148
|
:returnCdf => true).var("P").get
|
|
150
149
|
assert_equal(1013.25,sum.min)
|
|
151
|
-
sum = Cdo.fldsum(:
|
|
150
|
+
sum = Cdo.fldsum(:input => Cdo.stdatm(0,:options => "-f nc"),:output => ofile0)
|
|
152
151
|
assert_equal(ofile0,sum)
|
|
153
152
|
test_returnCdf
|
|
154
153
|
end
|
|
@@ -161,9 +160,9 @@ class TestCdo < Test::Unit::TestCase
|
|
|
161
160
|
|
|
162
161
|
# deticated output, force = true
|
|
163
162
|
outs.clear
|
|
164
|
-
outs << Cdo.stdatm(0,10,20,:
|
|
163
|
+
outs << Cdo.stdatm(0,10,20,:output => 'test_force')
|
|
165
164
|
mtime0 = File.stat(outs[-1]).mtime
|
|
166
|
-
outs << Cdo.stdatm(0,10,20,:
|
|
165
|
+
outs << Cdo.stdatm(0,10,20,:output => 'test_force')
|
|
167
166
|
mtime1 = File.stat(outs[-1]).mtime
|
|
168
167
|
assert_not_equal(mtime0,mtime1)
|
|
169
168
|
assert_equal(outs[0],outs[1])
|
|
@@ -172,9 +171,9 @@ class TestCdo < Test::Unit::TestCase
|
|
|
172
171
|
|
|
173
172
|
# dedicated output, force = false
|
|
174
173
|
ofile = 'test_force_false'
|
|
175
|
-
outs << Cdo.stdatm(0,10,20,:
|
|
174
|
+
outs << Cdo.stdatm(0,10,20,:output => ofile,:force => false)
|
|
176
175
|
mtime0 = File.stat(outs[-1]).mtime
|
|
177
|
-
outs << Cdo.stdatm(0,10,20,:
|
|
176
|
+
outs << Cdo.stdatm(0,10,20,:output => ofile,:force => false)
|
|
178
177
|
mtime1 = File.stat(outs[-1]).mtime
|
|
179
178
|
assert_equal(mtime0,mtime1)
|
|
180
179
|
assert_equal(outs[0],outs[1])
|
|
@@ -184,9 +183,9 @@ class TestCdo < Test::Unit::TestCase
|
|
|
184
183
|
# dedicated output, global force setting
|
|
185
184
|
ofile = 'test_force_global'
|
|
186
185
|
Cdo.forceOutput = false
|
|
187
|
-
outs << Cdo.stdatm(0,10,20,:
|
|
186
|
+
outs << Cdo.stdatm(0,10,20,:output => ofile)
|
|
188
187
|
mtime0 = File.stat(outs[-1]).mtime
|
|
189
|
-
outs << Cdo.stdatm(0,10,20,:
|
|
188
|
+
outs << Cdo.stdatm(0,10,20,:output => ofile)
|
|
190
189
|
mtime1 = File.stat(outs[-1]).mtime
|
|
191
190
|
assert_equal(mtime0,mtime1)
|
|
192
191
|
assert_equal(outs[0],outs[1])
|
|
@@ -197,42 +196,58 @@ class TestCdo < Test::Unit::TestCase
|
|
|
197
196
|
def test_thickness
|
|
198
197
|
levels = "25 100 250 500 875 1400 2100 3000 4000 5000".split
|
|
199
198
|
targetThicknesses = [50.0, 100.0, 200.0, 300.0, 450.0, 600.0, 800.0, 1000.0, 1000.0, 1000.0]
|
|
200
|
-
assert_equal(targetThicknesses, Cdo.thicknessOfLevels(:
|
|
199
|
+
assert_equal(targetThicknesses, Cdo.thicknessOfLevels(:input => "-selname,T -stdatm,#{levels.join(',')}"))
|
|
201
200
|
end
|
|
202
201
|
|
|
203
202
|
def test_showlevels
|
|
204
203
|
sourceLevels = %W{25 100 250 500 875 1400 2100 3000 4000 5000}
|
|
205
204
|
assert_equal(sourceLevels,
|
|
206
|
-
Cdo.showlevel(:
|
|
205
|
+
Cdo.showlevel(:input => "-selname,T #{Cdo.stdatm(*sourceLevels,:options => '-f nc')}")[0].split)
|
|
207
206
|
end
|
|
208
207
|
|
|
209
208
|
def test_verticalLevels
|
|
210
209
|
Cdo.debug = true
|
|
211
210
|
targetThicknesses = [50.0, 100.0, 200.0, 300.0, 450.0, 600.0, 800.0, 1000.0, 1000.0, 1000.0]
|
|
212
211
|
sourceLevels = %W{25 100 250 500 875 1400 2100 3000 4000 5000}
|
|
213
|
-
thicknesses = Cdo.thicknessOfLevels(:
|
|
212
|
+
thicknesses = Cdo.thicknessOfLevels(:input => "-selname,T #{Cdo.stdatm(*sourceLevels,:options => '-f nc')}")
|
|
214
213
|
assert_equal(targetThicknesses,thicknesses)
|
|
215
214
|
end
|
|
216
215
|
|
|
217
216
|
def test_parseArgs
|
|
218
|
-
io,opts = Cdo.parseArgs([1,2,3,:
|
|
219
|
-
assert_equal("1",io[:
|
|
220
|
-
assert_equal("2",io[:
|
|
217
|
+
io,opts = Cdo.parseArgs([1,2,3,:input => '1',:output => '2',:force => true,:returnCdf => "T"])
|
|
218
|
+
assert_equal("1",io[:input])
|
|
219
|
+
assert_equal("2",io[:output])
|
|
221
220
|
assert_equal(true,io[:force])
|
|
222
221
|
assert_equal("T",io[:returnCdf])
|
|
223
222
|
pp [io,opts]
|
|
224
223
|
end
|
|
225
224
|
|
|
225
|
+
def test_returnArray
|
|
226
|
+
temperature = Cdo.stdatm(0,:options => '-f nc',:returnCdf => true).var('T').get.flatten[0]
|
|
227
|
+
assert_raise ArgumentError do
|
|
228
|
+
Cdo.stdatm(0,:options => '-f nc',:returnArray => 'TT')
|
|
229
|
+
end
|
|
230
|
+
temperature = Cdo.stdatm(0,:options => '-f nc',:returnArray => 'T')
|
|
231
|
+
assert_equal(288.0,temperature.flatten[0])
|
|
232
|
+
pressure = Cdo.stdatm(0,1000,:options => '-f nc -b F64',:returnArray => 'P')
|
|
233
|
+
assert_equal("1013.25 898.543456035875",pressure.flatten.to_a.join(' '))
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
|
|
226
237
|
if 'thingol' == `hostname`.chomp then
|
|
227
238
|
def test_readCdf
|
|
228
239
|
input = "-settunits,days -setyear,2000 -for,1,4"
|
|
229
|
-
cdfFile = Cdo.copy(:options =>"-f nc",:
|
|
240
|
+
cdfFile = Cdo.copy(:options =>"-f nc",:input=>input)
|
|
230
241
|
cdf = Cdo.readCdf(cdfFile)
|
|
231
242
|
assert_equal(['lon','lat','time','for'],cdf.var_names)
|
|
232
243
|
end
|
|
233
244
|
def test_selIndexListFromIcon
|
|
234
245
|
input = "~/data/icon/oce.nc"
|
|
235
246
|
end
|
|
247
|
+
def test_readArray
|
|
248
|
+
ifile = '/home/ram/data/examples/EH5_AMIP_1_TSURF_1991-1995.nc'
|
|
249
|
+
assert_equal([192, 96, 10],Cdo.readArray(Cdo.seltimestep('1/10',:input => ifile), 'tsurf').shape)
|
|
250
|
+
end
|
|
236
251
|
end
|
|
237
252
|
|
|
238
253
|
end
|
|
@@ -241,30 +256,30 @@ end
|
|
|
241
256
|
# #
|
|
242
257
|
# # merge:
|
|
243
258
|
# # let files be an erray of valid filenames and ofile is a string
|
|
244
|
-
# Cdo.merge(:
|
|
259
|
+
# Cdo.merge(:input => outvars.join(" "),:output => ofile)
|
|
245
260
|
# # or with multiple arrays:
|
|
246
|
-
# Cdo.merge(:
|
|
261
|
+
# Cdo.merge(:input => [ifiles0,ifiles1].flatten.join(' '),:output => ofile)
|
|
247
262
|
# # selname:
|
|
248
263
|
# # lets grep out some variables from ifile:
|
|
249
264
|
# ["T","U","V"].each {|varname|
|
|
250
265
|
# varfile = varname+".nc"
|
|
251
|
-
# Cdo.selname(varname,:
|
|
266
|
+
# Cdo.selname(varname,:input => ifile,:output => varfile)
|
|
252
267
|
# }
|
|
253
268
|
# # a threaded version of this could look like:
|
|
254
269
|
# ths = []
|
|
255
270
|
# ["T","U","V"].each {|outvar|
|
|
256
271
|
# ths << Thread.new(outvar) {|ovar|
|
|
257
272
|
# varfile = varname+".nc"
|
|
258
|
-
# Cdo.selname(varname,:
|
|
273
|
+
# Cdo.selname(varname,:input => ifile,:output => varfile)
|
|
259
274
|
# }
|
|
260
275
|
# }
|
|
261
276
|
# ths.each {|th| th.join}
|
|
262
277
|
# # another example with sub:
|
|
263
|
-
# Cdo.sub(:
|
|
278
|
+
# Cdo.sub(:input => [oldfile,newfile].join(' '), :output => diff)
|
|
264
279
|
#
|
|
265
280
|
# # It is possible too use the 'send' method
|
|
266
281
|
# operator = /grb/.match(File.extname(ifile)) ? :showcode : :showname
|
|
267
|
-
# inputVars = Cdo.send(operator,:
|
|
282
|
+
# inputVars = Cdo.send(operator,:input => ifile)
|
|
268
283
|
# # show and info operators are writing to stdout. cdo.rb tries to collects this into arrays
|
|
269
284
|
# #
|
|
270
285
|
# # Same stuff with other operators:
|
|
@@ -274,15 +289,15 @@ end
|
|
|
274
289
|
# else
|
|
275
290
|
# warn "Wrong usage of variable identifier for '#{var}' (class #{var.class})!"
|
|
276
291
|
# end
|
|
277
|
-
# Cdo.send(operator,var,:
|
|
292
|
+
# Cdo.send(operator,var,:input => @ifile, :output => varfile)
|
|
278
293
|
#
|
|
279
294
|
# # Pass an array for operators with multiple options:
|
|
280
295
|
# # Perform conservative remapping with pregenerated weights
|
|
281
|
-
# Cdo.remap([gridfile,weightfile],:
|
|
296
|
+
# Cdo.remap([gridfile,weightfile],:input => copyfile,:output => outfile)
|
|
282
297
|
# # Create vertical height levels out of hybrid model levels
|
|
283
|
-
# Cdo.ml2hl([0,20,50,100,200,400,800,1200].join(','),:
|
|
298
|
+
# Cdo.ml2hl([0,20,50,100,200,400,800,1200].join(','),:input => hybridlayerfile, :output => reallayerfile)
|
|
284
299
|
# # or use multiple arguments directly
|
|
285
|
-
# Cdo.remapeta(vctfile,orofile,:
|
|
300
|
+
# Cdo.remapeta(vctfile,orofile,:input => ifile,:output => hybridlayerfile)
|
|
286
301
|
#
|
|
287
302
|
# # the powerfull expr operator:
|
|
288
303
|
# # taken from the tutorial in https://code.zmaw.de/projects/cdo/wiki/Tutorial#The-_expr_-Operator
|
|
@@ -293,8 +308,8 @@ end
|
|
|
293
308
|
# TEMP_EXPR = lambda {|height| "213.0+75.0*exp(-#{height}/#{SCALEHEIGHT})"}
|
|
294
309
|
#
|
|
295
310
|
# # Create Pressure and Temperature out of a height field 'geopotheight' from ifile
|
|
296
|
-
# Cdo.expr("'p=#{PRES_EXPR['geopotheight']}'", :
|
|
297
|
-
# Cdo.expr("'t=#{TEMP_EXPR['geopotheight']}'", :
|
|
311
|
+
# Cdo.expr("'p=#{PRES_EXPR['geopotheight']}'", :input => ifile, :output => presFile)
|
|
312
|
+
# Cdo.expr("'t=#{TEMP_EXPR['geopotheight']}'", :input => ifile, :output => tempFile)
|
|
298
313
|
#
|
|
299
314
|
#
|
|
300
315
|
# # TIPS: I often work with temporary files and for getting rid of handling them manually the MyTempfile module can be used:
|
|
@@ -304,8 +319,8 @@ end
|
|
|
304
319
|
# end
|
|
305
320
|
# # As an example, the computation of simple atmospherric density could look like
|
|
306
321
|
# presFile, tempFile = tfile, tfile
|
|
307
|
-
# Cdo.expr("'p=#{PRES_EXPR['geopotheight']}'", :
|
|
308
|
-
# Cdo.expr("'t=#{TEMP_EXPR['geopotheight']}'", :
|
|
322
|
+
# Cdo.expr("'p=#{PRES_EXPR['geopotheight']}'", :input => ifile, :output => presFile)
|
|
323
|
+
# Cdo.expr("'t=#{TEMP_EXPR['geopotheight']}'", :input => ifile, :output => tempFile)
|
|
309
324
|
# Cdo.chainCall("setname,#{rho} -divc,#{C_R} -div",in: [presFile,tempFile].join(' '), out: densityFile)
|
|
310
325
|
#
|
|
311
326
|
# # For debugging, it is helpfull, to avoid the automatic cleanup at the end of the scripts:
|
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.
|
|
4
|
+
version: 1.2.0
|
|
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-11-
|
|
12
|
+
date: 2012-11-21 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
|