Tutorial » ifs2icon_skel.rb
1 |
require 'cdo' |
---|---|
2 |
require 'jobqueue' |
3 |
|
4 |
iFile = ARGV[0].nil? ? 'ifs_oper_T1279_2011010100.grb' : ARGV[0] |
5 |
targetGridFile = ARGV[1].nil? ? 'cell_grid-r2b07.nc' : ARGV[1] |
6 |
targetGridweightsFile = ARGV[2].nil? ? 'cell_weight-r2b07.nc' : ARGV[2] |
7 |
nWorkers = ARGV[3].nil? ? 8 : ARGV[3] |
8 |
|
9 |
# lets work in debug mode
|
10 |
Cdo.debug = true |
11 |
|
12 |
# create a queue with a predifined number of workers
|
13 |
jq = JobQueue.new(nWorkers) |
14 |
|
15 |
# split the input file wrt to variable names,codes,levels,grids,timesteps,...
|
16 |
splitTag = "ifs2icon_skel_split_" |
17 |
#Cdo.splitcode(:in => iFile, :out => splitTag,:options => '-f nc')
|
18 |
Cdo.splitname(:in => iFile, :out => splitTag,:options => '-f nc') |
19 |
|
20 |
# collect Files form the split
|
21 |
files = Dir.glob("#{splitTag}*.nc") |
22 |
|
23 |
# remap variables in parallel
|
24 |
files.each {|file| |
25 |
jq.push { |
26 |
basename = file[0..-(File.extname(file).size+1)] |
27 |
Cdo.remap(targetGridFile,targetGridweightsFile, |
28 |
:in => file, |
29 |
:out => "remapped_#{basename}.nc") |
30 |
}
|
31 |
}
|
32 |
jq.run |
33 |
|
34 |
# Merge all the results together
|
35 |
Cdo.merge(:in => Dir.glob("remapped_*.nc").join(" "),:out => 'mergedResults.nc') |