cdo 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/gemspec +1 -1
  3. data/lib/cdo.rb +60 -2
  4. data/test/test_cdo.rb +36 -2
  5. metadata +8 -9
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 06d6492570a2bb4f02b81788514e61dc4fca1abc
4
+ data.tar.gz: 210c76b7cb096c5eb4d8e65672aa491b77152cc9
5
+ SHA512:
6
+ metadata.gz: 9beb317468976260445422c30644062908c763b530ac883e038003af764a1cd1873460680f436263c4d47ffb48296c58c1ce6e1b2f4d57ca158069ded712337d
7
+ data.tar.gz: 883ae4494bb3304c829c3ca082b04179ea6dc9d15702eabaeb5bf0c0045b81b256f914a81ec91f4c3c9749d321e63d91e38b3a538deeae0b0ff1f22a58bfb6b1
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.2.1'
6
+ s.version = '1.2.2'
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
@@ -17,11 +17,11 @@ require 'open3'
17
17
  # CDO calling mechnism
18
18
  module Cdo
19
19
 
20
- VERSION = "1.2.1"
20
+ VERSION = "1.2.2"
21
21
 
22
22
  State = {
23
23
  :debug => false,
24
- :returnCdf => false,
24
+ :returnCdf => false,
25
25
  :operators => [],
26
26
  :forceOutput => true
27
27
  }
@@ -103,6 +103,7 @@ module Cdo
103
103
  :returncode => wait_thr.value.exitstatus
104
104
  }
105
105
  end
106
+
106
107
  def Cdo.run(cmd,ofile='',options='',returnCdf=false,force=nil,returnArray=nil,returnMaArray=nil)
107
108
  cmd = "#{@@CDO} -O #{options} #{cmd} "
108
109
  case ofile
@@ -136,6 +137,7 @@ module Cdo
136
137
  return ofile
137
138
  end
138
139
  end
140
+
139
141
  def Cdo.parseArgs(args)
140
142
  # splitinto hash-like args and the rest
141
143
  operatorArgs = args.reject {|a| a.class == Hash}
@@ -143,8 +145,11 @@ module Cdo
143
145
  io = args.find {|a| a.class == Hash}
144
146
  io = {} if io.nil?
145
147
  args.delete_if {|a| a.class == Hash}
148
+ # join input streams together if possible
149
+ io[:input] = io[:input].join(' ') if io[:input].respond_to?(:join)
146
150
  return [io,opts]
147
151
  end
152
+
148
153
  def Cdo.method_missing(sym, *args, &block)
149
154
  ## args is expected to look like [opt1,...,optN,:input => iStream,:output => oStream] where
150
155
  # iStream could be another CDO call (timmax(selname(Temp,U,V,ifile.nc))
@@ -160,6 +165,7 @@ module Cdo
160
165
  raise ArgumentError,"Operator #{sym.to_s} not found"
161
166
  end
162
167
  end
168
+
163
169
  def Cdo.loadCdf
164
170
  begin
165
171
  require "numru/netcdf_miss"
@@ -170,19 +176,38 @@ module Cdo
170
176
  end
171
177
  end
172
178
 
179
+ def Cdo.getSupportedLibs(force=false)
180
+ return unless (State[:libs].nil? or force)
181
+ _, _, stderr, _ = Open3.popen3(@@CDO + " -V")
182
+ supported = stderr.readlines.map(&:chomp)
183
+ with = supported.grep(/with/)[0].split(':')[1].split.map(&:downcase)
184
+ libs = supported.grep(/library version/).map {|l|
185
+ l.strip.split(':').map {|l|
186
+ l.split.first.downcase
187
+ }[0,2]
188
+ }
189
+ State[:libs] = {}
190
+ with.flatten.each {|k| State[:libs][k]=true}
191
+ libs.each {|lib,version| State[:libs][lib] = version}
192
+ end
193
+
173
194
  public
174
195
  def Cdo.debug=(value)
175
196
  State[:debug] = value
176
197
  end
198
+
177
199
  def Cdo.debug
178
200
  State[:debug]
179
201
  end
202
+
180
203
  def Cdo.forceOutput=(value)
181
204
  State[:forceOutput] = value
182
205
  end
206
+
183
207
  def Cdo.forceOutput
184
208
  State[:forceOutput]
185
209
  end
210
+
186
211
  def Cdo.version
187
212
  cmd = @@CDO + ' 2>&1'
188
213
  help = IO.popen(cmd).readlines.map {|l| l.chomp.lstrip}
@@ -190,15 +215,18 @@ module Cdo
190
215
  line = help.find {|v| v =~ regexp}
191
216
  version = regexp.match(line)[1]
192
217
  end
218
+
193
219
  def Cdo.setReturnCdf(value=true)
194
220
  if value
195
221
  Cdo.loadCdf
196
222
  end
197
223
  State[:returnCdf] = value
198
224
  end
225
+
199
226
  def Cdo.unsetReturnCdf
200
227
  setReturnCdf(false)
201
228
  end
229
+
202
230
  def Cdo.returnCdf
203
231
  State[:returnCdf]
204
232
  end
@@ -221,19 +249,45 @@ module Cdo
221
249
  end
222
250
  return true
223
251
  end
252
+
224
253
  def Cdo.setCdo(cdo)
225
254
  puts "Will use #{cdo} instead of #@@CDO" if Cdo.debug
226
255
  @@CDO = cdo
227
256
  Cdo.getOperators(true)
228
257
  end
258
+
229
259
  def Cdo.getCdo
230
260
  @@CDO
231
261
  end
262
+
232
263
  def Cdo.operators
233
264
  Cdo.getOperators if State[:operators].empty?
234
265
  State[:operators]
235
266
  end
236
267
 
268
+ def Cdo.libs
269
+ getSupportedLibs
270
+ State[:libs]
271
+ end
272
+
273
+ def Cdo.hasLib?(lib)
274
+ return Cdo.libs.has_key?(lib)
275
+ return false
276
+ end
277
+
278
+ def Cdo.libsVersion(lib)
279
+ unless Cdo.hasLib?(lib)
280
+ raise ArgumentError, "Cdo does NOT have support for '#{lib}'"
281
+ else
282
+ if State[:libs][lib].kind_of? String
283
+ return State[:libs][lib]
284
+ else
285
+ warn "No version information available about '#{lib}'"
286
+ return false
287
+ end
288
+ end
289
+ end
290
+
237
291
  #==================================================================
238
292
  # Addional operotors:
239
293
  #------------------------------------------------------------------
@@ -281,6 +335,7 @@ module Cdo
281
335
  raise ArgumentError,"Cannot find variable '#{varname}'"
282
336
  end
283
337
  end
338
+
284
339
  def Cdo.help(operator=nil)
285
340
  if operator.nil?
286
341
  puts Cdo.call([@@CDO,'-h'].join(' '))[:stderr]
@@ -301,9 +356,11 @@ module MyTempfile
301
356
  @@_tempfiles = []
302
357
  @@persistent_tempfiles = false
303
358
  @@N = 10000000
359
+
304
360
  def MyTempfile.setPersist(value)
305
361
  @@persistent_tempfiles = value
306
362
  end
363
+
307
364
  def MyTempfile.path
308
365
  unless @@persistent_tempfiles
309
366
  t = Tempfile.new(self.class.to_s)
@@ -316,6 +373,7 @@ module MyTempfile
316
373
  t
317
374
  end
318
375
  end
376
+
319
377
  def MyTempfile.showFiles
320
378
  @@_tempfiles.each {|f| print(f+" ") if f.kind_of? String}
321
379
  end
data/test/test_cdo.rb CHANGED
@@ -76,8 +76,10 @@ class TestCdo < Test::Unit::TestCase
76
76
  names = Cdo.showname(:input => "-stdatm,0",:options => "-f nc")
77
77
  assert_equal(["P T"],names)
78
78
 
79
- ofile = Cdo.topo(:output => ofile,:options => "-z szip")
80
- assert_equal(["GRIB SZIP"],Cdo.showformat(:input => ofile))
79
+ if Cdo.hasLib?("sz")
80
+ ofile = Cdo.topo(:output => ofile,:options => "-z szip")
81
+ assert_equal(["GRIB SZIP"],Cdo.showformat(:input => ofile))
82
+ end
81
83
  end
82
84
  def test_chain
83
85
  Cdo.debug = true
@@ -282,6 +284,38 @@ class TestCdo < Test::Unit::TestCase
282
284
  end
283
285
  end
284
286
 
287
+ def test_inputArray
288
+ # check for file input
289
+ fileA = Cdo.stdatm(0)
290
+ fileB = Cdo.stdatm(0)
291
+ files = [fileA,fileB]
292
+ assert_equal(Cdo.diffv(:input => files.join(' ')),
293
+ Cdo.diffv(:input => files))
294
+ assert_equal("0 of 2 records differ",Cdo.diffv(:input => files).last)
295
+ # check for operator input
296
+ assert_equal("0 of 2 records differ",Cdo.diffv(:input => ["-stdatm,0","-stdatm,0"]).last)
297
+ # check for operator input and files
298
+ assert_equal("0 of 2 records differ",Cdo.diffv(:input => ["-stdatm,0",fileB]).last)
299
+ end
300
+
301
+ def test_libs
302
+ assert(Cdo.hasLib?("cdi"),"CDI support missing")
303
+ assert(Cdo.hasLib?("nc4"),"netcdf4 support missing")
304
+ assert(Cdo.hasLib?("netcdf"),"netcdf support missing")
305
+ assert_equal(false,Cdo.hasLib?("boost"))
306
+ if 'thingol' == `hostname`.chomp
307
+ assert_equal('1.10.0',Cdo.libsVersion("grib_api")) if Cdo.hasLib?("grib_api")
308
+ end
309
+ assert_raise ArgumentError do
310
+ Cdo.libsVersion("foo")
311
+ end
312
+ end
313
+
314
+ def test_output_set_to_nil
315
+ assert_equal(String,Cdo.topo(:output => nil).class)
316
+ assert_equal("File format: GRIB",Cdo.sinfov(:input => "-topo", :output => nil)[0])
317
+ end
318
+
285
319
  if 'thingol' == `hostname`.chomp then
286
320
  def test_readCdf
287
321
  input = "-settunits,days -setyear,2000 -for,1,4"
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cdo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
5
- prerelease:
4
+ version: 1.2.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ralf Mueller
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-05 00:00:00.000000000 Z
11
+ date: 2013-09-12 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Easy access to the Climate Data operators
15
14
  email: stark.dreamdetective@gmail.com
@@ -28,27 +27,27 @@ files:
28
27
  homepage: https://code.zmaw.de/projects/cdo/wiki/Cdo%7Brbpy%7D
29
28
  licenses:
30
29
  - GPLv2
30
+ metadata: {}
31
31
  post_install_message:
32
32
  rdoc_options: []
33
33
  require_paths:
34
34
  - lib
35
35
  required_ruby_version: !ruby/object:Gem::Requirement
36
- none: false
37
36
  requirements:
38
- - - ! '>='
37
+ - - '>='
39
38
  - !ruby/object:Gem::Version
40
39
  version: '1.9'
41
40
  required_rubygems_version: !ruby/object:Gem::Requirement
42
- none: false
43
41
  requirements:
44
- - - ! '>='
42
+ - - '>='
45
43
  - !ruby/object:Gem::Version
46
44
  version: '0'
47
45
  requirements: []
48
46
  rubyforge_project:
49
- rubygems_version: 1.8.23
47
+ rubygems_version: 2.0.3
50
48
  signing_key:
51
- specification_version: 3
49
+ specification_version: 4
52
50
  summary: Easy access to the Climate Data operators
53
51
  test_files:
54
52
  - test/test_cdo.rb
53
+ has_rdoc: