cdo 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/gemspec +1 -1
- data/lib/cdo.rb +30 -21
- data/test/test_cdo.rb +136 -179
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f41ea1d14a2640c9c93ca33eaeacb7860f39fd723e857f740dc366bc284f020
|
4
|
+
data.tar.gz: 2c5fb959227006a1659c7c6fa97936d85ddd5b62fc1e9c0459e9029c043c1819
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1fea4d7b5c61a989b6b7ecab617604ab4977f771b072b8441149bd141a4fa95e0cfc5cc1e520d34f3c644c4d21fe15092ac332719ed526a03fc3edd9be657d5
|
7
|
+
data.tar.gz: 7e687fc0d277d2123eb815012ad023d38480b631e0414f33503928d09e39fc0dc12a3b22e2d259bd23d0343d668c3d2a8d5b781ea200c9d65d66218022b6cab1
|
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.5.0'
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.files = ["lib/cdo.rb","gemspec","LICENSE"]
|
9
9
|
s.test_file = "test/test_cdo.rb"
|
data/lib/cdo.rb
CHANGED
@@ -35,18 +35,17 @@ class Cdo
|
|
35
35
|
|
36
36
|
|
37
37
|
attr_accessor :cdo, :returnCdf, :forceOutput, :env, :debug, :logging, :logFile
|
38
|
-
attr_reader :operators, :filetypes
|
38
|
+
attr_reader :operators, :filetypes, :hasNetcdf
|
39
39
|
|
40
40
|
def initialize(cdo: 'cdo',
|
41
|
-
returnCdf: false,
|
42
41
|
returnFalseOnError: false,
|
42
|
+
returnNilOnError: false,
|
43
43
|
forceOutput: true,
|
44
44
|
env: {},
|
45
|
+
debug: false,
|
45
46
|
tempdir: Dir.tmpdir,
|
46
47
|
logging: false,
|
47
|
-
logFile: StringIO.new
|
48
|
-
debug: false,
|
49
|
-
returnNilOnError: false)
|
48
|
+
logFile: StringIO.new)
|
50
49
|
|
51
50
|
# setup path to cdo executable
|
52
51
|
@cdo = ENV.has_key?('CDO') ? ENV['CDO'] : cdo
|
@@ -54,12 +53,12 @@ class Cdo
|
|
54
53
|
@operators = getOperators(@cdo)
|
55
54
|
@noOutputOperators = @operators.select {|op,io| 0 == io}.keys
|
56
55
|
|
57
|
-
@
|
56
|
+
@hasNetcdf = loadOptionalLibs
|
57
|
+
|
58
58
|
@forceOutput = forceOutput
|
59
59
|
@env = env
|
60
60
|
@debug = ENV.has_key?('DEBUG') ? true : debug
|
61
61
|
@returnNilOnError = returnNilOnError
|
62
|
-
|
63
62
|
@returnFalseOnError = returnFalseOnError
|
64
63
|
|
65
64
|
@tempStore = CdoTempfileStore.new(tempdir)
|
@@ -76,6 +75,13 @@ class Cdo
|
|
76
75
|
v
|
77
76
|
end
|
78
77
|
}
|
78
|
+
|
79
|
+
# ignore return code 1 for diff operators (from 1.9.6 onwards)
|
80
|
+
@exit_success = lambda {|operatorName|
|
81
|
+
return 0 if version < '1.9.6'
|
82
|
+
return 0 if 'diff' != operatorName[0,4]
|
83
|
+
return 1
|
84
|
+
}
|
79
85
|
end
|
80
86
|
|
81
87
|
private # {{{
|
@@ -209,11 +215,11 @@ class Cdo
|
|
209
215
|
end
|
210
216
|
|
211
217
|
# Error handling for the given command
|
212
|
-
def _hasError(cmd,retvals)
|
218
|
+
def _hasError(cmd,operatorName,retvals)
|
213
219
|
if @debug
|
214
220
|
puts("RETURNCODE: #{retvals[:returncode]}")
|
215
221
|
end
|
216
|
-
if (
|
222
|
+
if ( @exit_success[operatorName] < retvals[:returncode] )
|
217
223
|
puts("Error in calling:")
|
218
224
|
puts(">>> "+cmd+"<<<")
|
219
225
|
puts(retvals[:stderr])
|
@@ -260,7 +266,7 @@ class Cdo
|
|
260
266
|
case output
|
261
267
|
when $stdout
|
262
268
|
retvals = _call(cmd,env)
|
263
|
-
unless _hasError(cmd,retvals)
|
269
|
+
unless _hasError(cmd,operatorName,retvals)
|
264
270
|
_output = retvals[:stdout].split($/).map {|l| l.chomp.strip}
|
265
271
|
unless autoSplit.nil?
|
266
272
|
_output.map! {|line| line.split(autoSplit)}
|
@@ -290,7 +296,7 @@ class Cdo
|
|
290
296
|
|
291
297
|
retvals = _call(cmd,env)
|
292
298
|
|
293
|
-
if _hasError(cmd,retvals)
|
299
|
+
if _hasError(cmd,operatorName,retvals)
|
294
300
|
if @returnNilOnError then
|
295
301
|
return nil
|
296
302
|
else
|
@@ -309,7 +315,7 @@ class Cdo
|
|
309
315
|
readArray(outputs[0],returnArray)
|
310
316
|
elsif not returnMaArray.nil?
|
311
317
|
readMaArray(outputs[0],returnMaArray)
|
312
|
-
elsif returnCdf
|
318
|
+
elsif returnCdf
|
313
319
|
retval = outputs.map{|f| readCdf(f)}
|
314
320
|
return 1 == retval.size ? retval[0] : retval
|
315
321
|
elsif /^split/.match(operatorName)
|
@@ -344,12 +350,13 @@ class Cdo
|
|
344
350
|
end
|
345
351
|
|
346
352
|
# load the netcdf bindings
|
347
|
-
def
|
353
|
+
def loadOptionalLibs
|
348
354
|
begin
|
349
355
|
require "numru/netcdf_miss"
|
350
|
-
|
351
|
-
|
352
|
-
|
356
|
+
return true
|
357
|
+
rescue
|
358
|
+
warn "Could not load ruby's netcdf bindings"
|
359
|
+
return false
|
353
360
|
end
|
354
361
|
end
|
355
362
|
|
@@ -411,15 +418,17 @@ class Cdo
|
|
411
418
|
end
|
412
419
|
|
413
420
|
# return cdf handle to given file readonly
|
414
|
-
def readCdf(iFile)
|
415
|
-
|
416
|
-
|
421
|
+
def readCdf(iFile,mode='r')
|
422
|
+
if @hasNetcdf then
|
423
|
+
NumRu::NetCDF.open(iFile,mode)
|
424
|
+
else
|
425
|
+
raise LoadError,"Could not load ruby-netcdf"
|
426
|
+
end
|
417
427
|
end
|
418
428
|
|
419
429
|
# return cdf handle opened in append more
|
420
430
|
def openCdf(iFile)
|
421
|
-
|
422
|
-
NumRu::NetCDF.open(iFile,'r+')
|
431
|
+
readCdf(iFile,'r+')
|
423
432
|
end
|
424
433
|
|
425
434
|
# return narray for given variable name
|
data/test/test_cdo.rb
CHANGED
@@ -66,6 +66,14 @@ class TestCdo < Minitest::Test
|
|
66
66
|
assert(@cdo.operators.size > 700,"cound not find enough operators")
|
67
67
|
end
|
68
68
|
|
69
|
+
def test_verifyGridOP
|
70
|
+
if "1.9.5" >= @cdo.version then
|
71
|
+
assert(@cdo.operators.keys.include?('gridverify'))
|
72
|
+
else
|
73
|
+
assert(@cdo.operators.keys.include?('verifygrid'))
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
69
77
|
def test_outputOperators
|
70
78
|
@cdo.debug = @@debug
|
71
79
|
levels = @cdo.showlevel(:input => "-stdatm,0")
|
@@ -214,11 +222,11 @@ class TestCdo < Minitest::Test
|
|
214
222
|
end
|
215
223
|
|
216
224
|
def test_parseArgs
|
217
|
-
io,opts = Cdo.parseArgs([1,2,3,:input => '1',:output => '2',:force => true,:returnCdf =>
|
225
|
+
io,opts = Cdo.parseArgs([1,2,3,:input => '1',:output => '2',:force => true,:returnCdf => true,:autoSplit => ' '])
|
218
226
|
assert_equal("1",io[:input])
|
219
227
|
assert_equal("2",io[:output])
|
220
228
|
assert_equal(true,io[:force])
|
221
|
-
assert_equal(
|
229
|
+
assert_equal(true,io[:returnCdf])
|
222
230
|
assert_equal(" ",io[:autoSplit])
|
223
231
|
pp [io,opts]
|
224
232
|
end
|
@@ -273,7 +281,7 @@ class TestCdo < Minitest::Test
|
|
273
281
|
|
274
282
|
def test_noOutputOps
|
275
283
|
operators = @cdo.operators
|
276
|
-
%w[griddes griddes2
|
284
|
+
%w[griddes griddes2 info infoc infon infop infos infov map
|
277
285
|
outputarr outputbounds outputboundscpt outputcenter outputcenter2
|
278
286
|
outputcentercpt outputext outputf outputfld outputint outputkey outputsrv
|
279
287
|
outputtab outputtri outputts outputvector outputvrml outputxyz pardes partab].each {|op|
|
@@ -355,91 +363,104 @@ class TestCdo < Minitest::Test
|
|
355
363
|
end
|
356
364
|
|
357
365
|
def test_returnArray
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
366
|
+
if @cdo.hasNetcdf then
|
367
|
+
temperature = @cdo.stdatm(0,:returnCdf => true).var('T').get.flatten[0]
|
368
|
+
assert(1.7 < temperature,"Temperature to low!")
|
369
|
+
assert_raises ArgumentError do
|
370
|
+
@cdo.stdatm(0,:returnArray => 'TT')
|
371
|
+
end
|
372
|
+
temperature = @cdo.stdatm(0,:returnArray => 'T')
|
373
|
+
assert_equal(288.0,temperature.flatten[0])
|
374
|
+
pressure = @cdo.stdatm(0,1000,:options => '-b F64',:returnArray => 'P')
|
375
|
+
assert_equal("1013.25 898.543456035875",pressure.flatten.to_a.join(' '))
|
376
|
+
else
|
377
|
+
assert_raises LoadError do
|
378
|
+
temperature = @cdo.stdatm(0,:returnCdf => true).var('T').get.flatten[0]
|
379
|
+
end
|
362
380
|
end
|
363
|
-
temperature = @cdo.stdatm(0,:returnArray => 'T')
|
364
|
-
assert_equal(288.0,temperature.flatten[0])
|
365
|
-
pressure = @cdo.stdatm(0,1000,:options => '-b F64',:returnArray => 'P')
|
366
|
-
assert_equal("1013.25 898.543456035875",pressure.flatten.to_a.join(' '))
|
367
381
|
end
|
368
382
|
def test_returnMaArray
|
369
|
-
@cdo.
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
@tempStore.showFiles
|
395
|
-
diff = @cdo.sub(:input => [ofile0,ofile1].join(' ')).var('T').get
|
396
|
-
assert_equal(0.0,diff.min)
|
397
|
-
assert_equal(0.0,diff.max)
|
398
|
-
@cdo.returnCdf = false
|
383
|
+
if @cdo.hasNetcdf then
|
384
|
+
@cdo.debug = @@debug
|
385
|
+
topo = @cdo.topo(:returnMaArray => 'topo')
|
386
|
+
assert_equal(-1890.0,topo.mean.round)
|
387
|
+
bathy = @cdo.setrtomiss(0,10000,
|
388
|
+
:input => @cdo.topo(:options => '-f nc'),:returnMaArray => 'topo')
|
389
|
+
assert_equal(-3386.0,bathy.mean.round)
|
390
|
+
oro = @cdo.setrtomiss(-10000,0,
|
391
|
+
:input => @cdo.topo(:options => '-f nc'),:returnMaArray => 'topo')
|
392
|
+
assert_equal(1142.0,oro.mean.round)
|
393
|
+
bathy = @cdo.remapnn('r2x2',:input => @cdo.topo(:options => '-f nc'), :returnMaArray => 'topo')
|
394
|
+
assert_equal(-4298.0,bathy[0,0])
|
395
|
+
assert_equal(-2669.0,bathy[1,0])
|
396
|
+
ta = @cdo.remapnn('r2x2',:input => @cdo.topo(:options => '-f nc'))
|
397
|
+
tb = @cdo.subc(-2669.0,:input => ta)
|
398
|
+
withMask = @cdo.div(:input => ta+" "+tb,:returnMaArray => 'topo')
|
399
|
+
assert(-8.0e+33 > withMask[1,0])
|
400
|
+
assert(0 < withMask[0,0])
|
401
|
+
assert(0 < withMask[0,1])
|
402
|
+
assert(0 < withMask[1,1])
|
403
|
+
else
|
404
|
+
assert_raises LoadError do
|
405
|
+
topo = @cdo.topo(:returnMaArray => 'topo')
|
406
|
+
end
|
407
|
+
end
|
399
408
|
end
|
400
409
|
|
401
410
|
def test_returnCdf
|
402
411
|
ofile = rand(0xfffff).to_s + '_test_returnCdf.nc'
|
403
412
|
vals = @cdo.stdatm(25,100,250,500,875,1400,2100,3000,4000,5000,:output => ofile,:options => "-f nc")
|
404
413
|
assert_equal(ofile,vals)
|
405
|
-
@cdo.
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
414
|
+
if @cdo.hasNetcdf then
|
415
|
+
vals = @cdo.stdatm(25,100,250,500,875,1400,2100,3000,4000,5000,:output => ofile,:returnCdf => true)
|
416
|
+
assert_equal(["lon","lat","level","P","T"],vals.var_names)
|
417
|
+
assert_equal(276,vals.var("T").get.flatten.mean.floor)
|
418
|
+
vals = @cdo.stdatm(25,100,250,500,875,1400,2100,3000,4000,5000,:output => ofile,:options => "-f nc")
|
419
|
+
assert_equal(ofile,vals)
|
420
|
+
end
|
412
421
|
FileUtils.rm(ofile)
|
413
422
|
end
|
414
423
|
def test_simple_returnCdf
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
424
|
+
if @cdo.hasNetcdf then
|
425
|
+
ofile0, ofile1 = @tempStore.newFile, @tempStore.newFile
|
426
|
+
sum = @cdo.fldsum(:input => @cdo.stdatm(0,:options => "-f nc"),
|
427
|
+
:returnCdf => true).var("P").get
|
428
|
+
assert_equal(1013.25,sum.min)
|
429
|
+
sum = @cdo.fldsum(:input => @cdo.stdatm(0,:options => "-f nc"),:output => ofile0)
|
430
|
+
assert_equal(ofile0,sum)
|
431
|
+
test_returnCdf
|
432
|
+
else
|
433
|
+
puts "test_simple_returnCdf is disabled because of missing ruby-netcdf"
|
434
|
+
end
|
422
435
|
end
|
423
436
|
def test_readCdf
|
424
437
|
input = "-settunits,days -setyear,2000 -for,1,4"
|
425
438
|
cdfFile = @cdo.copy(:options =>"-f nc",:input=>input)
|
426
|
-
|
427
|
-
|
439
|
+
if @cdo.hasNetcdf then
|
440
|
+
cdf = @cdo.readCdf(cdfFile)
|
441
|
+
assert_empty(['lon','lat','for','time'] - cdf.var_names)
|
442
|
+
else
|
443
|
+
assert_raises LoadError do
|
444
|
+
cdf = @cdo.readCdf(cdfFile)
|
445
|
+
end
|
446
|
+
end
|
428
447
|
end
|
429
448
|
def test_combine
|
430
449
|
ofile0, ofile1 = @tempStore.newFile, @tempStore.newFile
|
431
450
|
@cdo.fldsum(:input => @cdo.stdatm(25,100,250,500,875,1400,2100,3000,4000,5000,:options => "-f nc"),:output => ofile0)
|
432
451
|
@cdo.fldsum(:input => "-stdatm,25,100,250,500,875,1400,2100,3000,4000,5000",:options => "-f nc",:output => ofile1)
|
433
|
-
@cdo.returnCdf = true
|
434
452
|
@tempStore.showFiles
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
453
|
+
if @cdo.hasNetcdf then
|
454
|
+
diff = @cdo.sub(:returnCdf => true, :input => [ofile0,ofile1].join(' ')).var('T').get
|
455
|
+
assert_equal(0.0,diff.min)
|
456
|
+
assert_equal(0.0,diff.max)
|
457
|
+
end
|
439
458
|
end
|
440
459
|
def test_readArray
|
441
|
-
@cdo.
|
442
|
-
|
460
|
+
if @cdo.hasNetcdf then
|
461
|
+
@cdo.debug = @@debug
|
462
|
+
assert_equal([40,80],@cdo.readArray(@cdo.sellonlatbox(-10,10,-20,20,:input => '-topo',:options => '-f nc'), 'topo').shape)
|
463
|
+
end
|
443
464
|
end
|
444
465
|
def test_env
|
445
466
|
oTag = 'test_env_with_splitlevel_'
|
@@ -557,45 +578,57 @@ class TestCdo < Minitest::Test
|
|
557
578
|
@cdo.help
|
558
579
|
end
|
559
580
|
def test_fillmiss
|
560
|
-
@cdo.
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
581
|
+
rand = @cdo.setname('v',
|
582
|
+
:input => '-random,r1x10 ',
|
583
|
+
:options => ' -f nc')
|
584
|
+
|
585
|
+
if @cdo.hasNetcdf then
|
586
|
+
@cdo.debug = @@debug
|
587
|
+
cdf = @cdo.openCdf(rand)
|
588
|
+
vals = cdf.var('v').get
|
589
|
+
cdf.var('v').put(vals.sort)
|
590
|
+
cdf.sync
|
591
|
+
cdf.close
|
592
|
+
else
|
593
|
+
assert_raises LoadError do
|
594
|
+
cdf = @cdo.openCdf(rand)
|
595
|
+
end
|
596
|
+
end
|
597
|
+
|
598
|
+
if @cdo.hasNetcdf then
|
599
|
+
missRange = '0.3,0.8'
|
600
|
+
arOrg = @cdo.setrtomiss(missRange,:input => cdf.path,:returnMaArray => 'v')
|
601
|
+
arFm = @cdo.fillmiss(:input => "-setrtomiss,#{missRange} #{cdf.path}",:returnMaArray => 'v')
|
602
|
+
arFm1s= @cdo.fillmiss2(:input => "-setrtomiss,#{missRange} #{cdf.path}",:returnMaArray => 'v')
|
603
|
+
vOrg = arOrg[0,0..-1]
|
604
|
+
vFm = arFm[0,0..-1]
|
605
|
+
vFm1s = arFm1s[0,0..-1]
|
606
|
+
UnifiedPlot.linePlot([{:y => vOrg, :style => 'line',:title => 'org'},
|
607
|
+
{:y => vFm, :style => 'points',:title => 'fillmiss'},
|
608
|
+
{:y => vFm1s,:style => 'points',:title => 'fillmiss2'}],
|
609
|
+
plotConf: {:yrange => '[0:1]'},title: 'r1x10') if @@show
|
610
|
+
# check left-right replacement
|
611
|
+
rm([rand])
|
612
|
+
rand = @cdo.setname('v',:input => '-random,r10x1 ', :options => ' -f nc',:output => '/tmp/rand.nc')
|
613
|
+
cdf = @cdo.openCdf(rand)
|
614
|
+
vals = cdf.var('v').get
|
615
|
+
cdf.var('v').put(vals.sort)
|
616
|
+
cdf.sync
|
617
|
+
cdf.close
|
618
|
+
|
619
|
+
missRange = '0.3,0.8'
|
620
|
+
arOrg = @cdo.setrtomiss(missRange,:input => cdf.path,:returnMaArray => 'v')
|
621
|
+
arFm = @cdo.fillmiss(:input => "-setrtomiss,#{missRange} #{cdf.path}",:returnMaArray => 'v')
|
622
|
+
arFm1s= @cdo.fillmiss2(:input => "-setrtomiss,#{missRange} #{cdf.path}",:returnMaArray => 'v')
|
623
|
+
vOrg = arOrg[0..-1,0]
|
624
|
+
vFm = arFm[0..-1,0]
|
625
|
+
vFm1s = arFm1s[0..-1,0]
|
626
|
+
UnifiedPlot.linePlot([{:y => vOrg, :style => 'line',:title => 'org'},
|
627
|
+
{:y => vFm, :style => 'points',:title => 'fillmiss'},
|
628
|
+
{:y => vFm1s,:style => 'points',:title => 'fillmiss2'}],
|
629
|
+
plotConf: {:yrange => '[0:1]'},title: 'r10x1') if @@show
|
630
|
+
rm([rand])
|
631
|
+
end
|
599
632
|
end
|
600
633
|
|
601
634
|
# opendap test - broken since 1.9.0
|
@@ -605,79 +638,3 @@ class TestCdo < Minitest::Test
|
|
605
638
|
end if @@debug
|
606
639
|
end
|
607
640
|
end
|
608
|
-
|
609
|
-
# # Calling simple operators
|
610
|
-
# #
|
611
|
-
# # merge:
|
612
|
-
# # let files be an erray of valid filenames and ofile is a string
|
613
|
-
# @cdo.merge(:input => outvars.join(" "),:output => ofile)
|
614
|
-
# # or with multiple arrays:
|
615
|
-
# @cdo.merge(:input => [ifiles0,ifiles1].flatten.join(' '),:output => ofile)
|
616
|
-
# # selname:
|
617
|
-
# # lets grep out some variables from ifile:
|
618
|
-
# ["T","U","V"].each {|varname|
|
619
|
-
# varfile = varname+".nc"
|
620
|
-
# @cdo.selname(varname,:input => ifile,:output => varfile)
|
621
|
-
# }
|
622
|
-
# # a threaded version of this could look like:
|
623
|
-
# ths = []
|
624
|
-
# ["T","U","V"].each {|outvar|
|
625
|
-
# ths << Thread.new(outvar) {|ovar|
|
626
|
-
# varfile = varname+".nc"
|
627
|
-
# @cdo.selname(varname,:input => ifile,:output => varfile)
|
628
|
-
# }
|
629
|
-
# }
|
630
|
-
# ths.each {|th| th.join}
|
631
|
-
# # another example with sub:
|
632
|
-
# @cdo.sub(:input => [oldfile,newfile].join(' '), :output => diff)
|
633
|
-
#
|
634
|
-
# # It is possible too use the 'send' method
|
635
|
-
# operator = /grb/.match(File.extname(ifile)) ? :showcode : :showname
|
636
|
-
# inputVars = @cdo.send(operator,:input => ifile)
|
637
|
-
# # show and info operators are writing to stdout. cdo.rb tries to collects this into arrays
|
638
|
-
# #
|
639
|
-
# # Same stuff with other operators:
|
640
|
-
# operator = case var
|
641
|
-
# when Fixnum then 'selcode'
|
642
|
-
# when String then 'selname'
|
643
|
-
# else
|
644
|
-
# warn "Wrong usage of variable identifier for '#{var}' (class #{var.class})!"
|
645
|
-
# end
|
646
|
-
# @cdo.send(operator,var,:input => @ifile, :output => varfile)
|
647
|
-
#
|
648
|
-
# # Pass an array for operators with multiple options:
|
649
|
-
# # Perform conservative remapping with pregenerated weights
|
650
|
-
# @cdo.remap([gridfile,weightfile],:input => copyfile,:output => outfile)
|
651
|
-
# # Create vertical height levels out of hybrid model levels
|
652
|
-
# @cdo.ml2hl([0,20,50,100,200,400,800,1200].join(','),:input => hybridlayerfile, :output => reallayerfile)
|
653
|
-
# # or use multiple arguments directly
|
654
|
-
# @cdo.remapeta(vctfile,orofile,:input => ifile,:output => hybridlayerfile)
|
655
|
-
#
|
656
|
-
# # the powerfull expr operator:
|
657
|
-
# # taken from the tutorial in https://code.zmaw.de/projects/cdo/wiki/Tutorial#The-_expr_-Operator
|
658
|
-
# SCALEHEIGHT = 10000.0
|
659
|
-
# C_EARTH_GRAV = 9.80665
|
660
|
-
# # function for later computation of hydrostatic atmosphere pressure
|
661
|
-
# PRES_EXPR = lambda {|height| "101325.0*exp((-1)*(1.602769777072154)*log((exp(#{height}/#{SCALEHEIGHT})*213.15+75.0)/288.15))"}
|
662
|
-
# TEMP_EXPR = lambda {|height| "213.0+75.0*exp(-#{height}/#{SCALEHEIGHT})"}
|
663
|
-
#
|
664
|
-
# # Create Pressure and Temperature out of a height field 'geopotheight' from ifile
|
665
|
-
# @cdo.expr("'p=#{PRES_EXPR['geopotheight']}'", :input => ifile, :output => presFile)
|
666
|
-
# @cdo.expr("'t=#{TEMP_EXPR['geopotheight']}'", :input => ifile, :output => tempFile)
|
667
|
-
#
|
668
|
-
#
|
669
|
-
# # TIPS: I often work with temporary files and for getting rid of handling them manually the CdoTempfileStore module can be used:
|
670
|
-
# # Simply include the following methods into you scripts and use tfile for any temporary variable
|
671
|
-
# def tfile
|
672
|
-
# CdoTempfileStore.path
|
673
|
-
# end
|
674
|
-
# # As an example, the computation of simple atmospherric density could look like
|
675
|
-
# presFile, tempFile = tfile, tfile
|
676
|
-
# @cdo.expr("'p=#{PRES_EXPR['geopotheight']}'", :input => ifile, :output => presFile)
|
677
|
-
# @cdo.expr("'t=#{TEMP_EXPR['geopotheight']}'", :input => ifile, :output => tempFile)
|
678
|
-
# @cdo.chainCall("setname,#{rho} -divc,#{C_R} -div",in: [presFile,tempFile].join(' '), out: densityFile)
|
679
|
-
#
|
680
|
-
# # For debugging, it is helpfull, to avoid the automatic cleanup at the end of the scripts:
|
681
|
-
# CdoTempfileStore.setPersist(true)
|
682
|
-
# # creates randomly names files. Switch on debugging with
|
683
|
-
# @cdo.Debug = true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cdo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ralf Mueller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unifiedPlot
|
@@ -109,8 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
|
-
|
113
|
-
rubygems_version: 2.7.4
|
112
|
+
rubygems_version: 3.0.2
|
114
113
|
signing_key:
|
115
114
|
specification_version: 4
|
116
115
|
summary: Easy access to the Climate Data operators
|