cdo 1.3.0 → 1.3.1

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 +14 -10
  4. data/test/test_cdo.rb +11 -6
  5. metadata +11 -15
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 287002a4182d792a1e88e67a710bc62b8a4a02d2
4
+ data.tar.gz: 86b007202f2872033207d264f3332880ff162199
5
+ SHA512:
6
+ metadata.gz: 0f921f437cbfa4a7c33b6424fe04623a873979aadb1dc33075a733c38b5856250b8ca612f847402b81945c0d6a7b016617850703145d264fb044aba4f1bbd322
7
+ data.tar.gz: 10e9c2af264a497d737923ee6fe75ebf1633fe9d04a9c43fe1aece6a2c7b14b10068eac4f15ed6fead7d9b265e449edb5c2d5746c18d5adfa0742afad9f10871
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.3.0'
6
+ s.version = '1.3.1'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.files = ["lib/cdo.rb","lib/cdo_lib.rb"] + ["gemspec","LICENSE"]
9
9
  s.test_file = "test/test_cdo.rb"
data/lib/cdo.rb CHANGED
@@ -43,14 +43,14 @@ class Cdo
43
43
  # split arguments into hash-like args and the rest
44
44
  def Cdo.parseArgs(args)
45
45
  operatorArgs = args.reject {|a| a.class == Hash}
46
- opts = operatorArgs.empty? ? '' : ',' + operatorArgs.join(',')
46
+ opArguments = operatorArgs.empty? ? '' : ',' + operatorArgs.join(',')
47
47
  io = args.find {|a| a.class == Hash}
48
48
  io = {} if io.nil?
49
- args.delete_if {|a| a.class == Hash}
49
+ #args.delete_if {|a| a.class == Hash}
50
50
  # join input streams together if possible
51
51
  io[:input] = io[:input].join(' ') if io[:input].respond_to?(:join)
52
52
 
53
- return [io,opts]
53
+ return [io,opArguments]
54
54
  end
55
55
 
56
56
  # collect the complete list of possible operators
@@ -82,10 +82,11 @@ class Cdo
82
82
 
83
83
 
84
84
  # Execute the given cdo call and return all outputs
85
- def _call(cmd)
85
+ def _call(cmd,env={})
86
86
  if (@debug)
87
87
  puts '# DEBUG ====================================================================='
88
88
  pp @env unless @env.empty?
89
+ pp env unless env.empty?
89
90
  puts 'CMD: '
90
91
  puts cmd
91
92
  puts '# DEBUG ====================================================================='
@@ -93,7 +94,7 @@ class Cdo
93
94
 
94
95
  @logger.info(cmd+"\n") if @logging
95
96
 
96
- stdin, stdout, stderr, wait_thr = Open3.popen3(@env,cmd)
97
+ stdin, stdout, stderr, wait_thr = Open3.popen3(@env.merge(env),cmd)
97
98
  {
98
99
  :stdout => stdout.read,
99
100
  :stderr => stderr.read,
@@ -118,7 +119,7 @@ class Cdo
118
119
  end
119
120
 
120
121
  # command execution wrapper, which handles the possible return types
121
- def _run(cmd,ofile='',options=nil,returnCdf=false,force=nil,returnArray=nil,returnMaArray=nil)
122
+ def _run(cmd,ofile='',options=nil,returnCdf=false,force=nil,returnArray=nil,returnMaArray=nil,env=nil)
122
123
  options = options.to_s
123
124
 
124
125
  options << '-f nc' if options.empty? and ( \
@@ -128,9 +129,12 @@ class Cdo
128
129
  )
129
130
  cmd = "#{@cdo} -O #{options} #{cmd} "
130
131
 
132
+ # use an empty hash for non-given environment
133
+ env = {} if env.nil?
134
+
131
135
  case ofile
132
136
  when $stdout
133
- retvals = _call(cmd)
137
+ retvals = _call(cmd,env)
134
138
  unless _hasError(cmd,retvals)
135
139
  return retvals[:stdout].split($/).map {|l| l.chomp.strip}
136
140
  else
@@ -145,7 +149,7 @@ class Cdo
145
149
  if force or not File.exists?(ofile.to_s)
146
150
  ofile = MyTempfile.path if ofile.nil?
147
151
  cmd << "#{ofile}"
148
- retvals = _call(cmd)
152
+ retvals = _call(cmd,env)
149
153
  if _hasError(cmd,retvals)
150
154
  if @returnNilOnError then
151
155
  return nil
@@ -180,9 +184,9 @@ class Cdo
180
184
  if @operators.include?(sym.to_s)
181
185
  io, opts = Cdo.parseArgs(args)
182
186
  if OutputOperatorsPattern.match(sym.to_s)
183
- _run(" -#{sym.to_s}#{opts} #{io[:input]} ",$stdout)
187
+ _run(" -#{sym.to_s}#{opts} #{io[:input]} ",$stdout,nil,nil,nil,nil,nil,env)
184
188
  else
185
- _run(" -#{sym.to_s}#{opts} #{io[:input]} ",io[:output],io[:options],io[:returnCdf],io[:force],io[:returnArray],io[:returnMaArray])
189
+ _run(" -#{sym.to_s}#{opts} #{io[:input]} ",io[:output],io[:options],io[:returnCdf],io[:force],io[:returnArray],io[:returnMaArray],io[:env])
186
190
  end
187
191
  else
188
192
  return false if @returnFalseOnError
data/test/test_cdo.rb CHANGED
@@ -9,12 +9,14 @@ require 'pp'
9
9
  #===============================================================================
10
10
  def rm(files); files.each {|f| FileUtils.rm(f) if File.exists?(f)};end
11
11
 
12
- @show = ENV.has_key?('SHOW')
13
12
 
14
13
  class TestCdo < Minitest::Test
15
14
 
16
15
  DEFAULT_CDO_PATH = 'cdo'
17
16
 
17
+ @@show = ENV.has_key?('SHOW')
18
+ @@maintainermode = ENV.has_key?('MAINTAINERMODE')
19
+
18
20
  def setup
19
21
  @cdo = Cdo.new
20
22
  end
@@ -32,6 +34,9 @@ class TestCdo < Minitest::Test
32
34
  assert_equal(true,cdo.check)
33
35
  assert_equal(newCDO,cdo.cdo)
34
36
  end
37
+ pp 'MAINTAINERMODE: '
38
+ pp @@maintainermode
39
+ pp @@show
35
40
  end
36
41
  def test_getOperators
37
42
  %w[for random stdatm info showlevel sinfo remap geopotheight mask topo thicknessOfLevels].each {|op|
@@ -310,7 +315,7 @@ class TestCdo < Minitest::Test
310
315
  assert_equal("File format: GRIB".tr(' ',''),@cdo.sinfov(:input => "-topo", :output => nil)[0].tr(' ',''))
311
316
  end
312
317
 
313
- if 'luthien' == `hostname`.chomp then
318
+ if @@maintainermode then
314
319
  def test_readCdf
315
320
  input = "-settunits,days -setyear,2000 -for,1,4"
316
321
  cdfFile = @cdo.copy(:options =>"-f nc",:input=>input)
@@ -352,7 +357,7 @@ class TestCdo < Minitest::Test
352
357
  UnifiedPlot.linePlot([{:y => vOrg, :style => 'line',:title => 'org'},
353
358
  {:y => vFm, :style => 'points',:title => 'fillmiss'},
354
359
  {:y => vFm1s,:style => 'points',:title => 'fillmiss2'}],
355
- plotConf: {:yrange => '[0:1]'},title: 'r1x10') if @show
360
+ plotConf: {:yrange => '[0:1]'},title: 'r1x10') if @@show
356
361
  # check left-right replacement
357
362
  rand = @cdo.setname('v',:input => '-random,r10x1 ', :options => ' -f nc',:output => '/tmp/rand.nc')
358
363
  cdf = @cdo.openCdf(rand)
@@ -371,7 +376,7 @@ class TestCdo < Minitest::Test
371
376
  UnifiedPlot.linePlot([{:y => vOrg, :style => 'line',:title => 'org'},
372
377
  {:y => vFm, :style => 'points',:title => 'fillmiss'},
373
378
  {:y => vFm1s,:style => 'points',:title => 'fillmiss2'}],
374
- plotConf: {:yrange => '[0:1]'},title: 'r10x1') if @show
379
+ plotConf: {:yrange => '[0:1]'},title: 'r10x1') if @@show
375
380
  end
376
381
  end
377
382
 
@@ -408,8 +413,8 @@ class TestCdo < Minitest::Test
408
413
  rm(ofiles)
409
414
 
410
415
  # oType = nc, from input ENV setting for each call
411
- ofiles = expected.map {|f| f += '.nc2'}
412
- @cdo.splitlevel(input: @cdo.stdatm(0,10,100,options: '-f nc'),output: oTag,env: {'CDO_FILE_SUFFIX' => '.nc2'})
416
+ ofiles = expected.map {|f| f += '.nc4'}
417
+ @cdo.splitlevel(input: @cdo.stdatm(0,10,100,options: '-f nc'),output: oTag,env: {'CDO_FILE_SUFFIX' => '.nc4'})
413
418
  assert_equal(ofiles,Dir.glob(oTag+'*').sort)
414
419
  rm(ofiles)
415
420
  end
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cdo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
5
- prerelease:
4
+ version: 1.3.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ralf Mueller
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2016-01-22 00:00:00.000000000 Z
11
+ date: 2016-07-11 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: unifiedPlot
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  description: Easy access to the Climate Data operators
@@ -33,35 +30,34 @@ executables: []
33
30
  extensions: []
34
31
  extra_rdoc_files: []
35
32
  files:
33
+ - LICENSE
34
+ - gemspec
36
35
  - lib/cdo.rb
37
36
  - lib/cdo_lib.rb
38
- - gemspec
39
- - LICENSE
40
37
  - test/test_cdo.rb
41
38
  homepage: https://code.zmaw.de/projects/cdo/wiki/Cdo%7Brbpy%7D
42
39
  licenses:
43
40
  - GPLv2
41
+ metadata: {}
44
42
  post_install_message:
45
43
  rdoc_options: []
46
44
  require_paths:
47
45
  - lib
48
46
  required_ruby_version: !ruby/object:Gem::Requirement
49
- none: false
50
47
  requirements:
51
- - - ! '>='
48
+ - - ">="
52
49
  - !ruby/object:Gem::Version
53
50
  version: '1.9'
54
51
  required_rubygems_version: !ruby/object:Gem::Requirement
55
- none: false
56
52
  requirements:
57
- - - ! '>='
53
+ - - ">="
58
54
  - !ruby/object:Gem::Version
59
55
  version: '0'
60
56
  requirements: []
61
57
  rubyforge_project:
62
- rubygems_version: 1.8.23.2
58
+ rubygems_version: 2.5.1
63
59
  signing_key:
64
- specification_version: 3
60
+ specification_version: 4
65
61
  summary: Easy access to the Climate Data operators
66
62
  test_files:
67
63
  - test/test_cdo.rb