Project

General

Profile

Tutorial » ifs2icon_skel.rb

Ralf Mueller, 2012-09-12 10:24

 
require 'cdo'
require 'jobqueue'

iFile = ARGV[0].nil? ? 'ifs_oper_T1279_2011010100.grb' : ARGV[0]
targetGridFile = ARGV[1].nil? ? 'cell_grid-r2b07.nc' : ARGV[1]
targetGridweightsFile = ARGV[2].nil? ? 'cell_weight-r2b07.nc' : ARGV[2]
nWorkers = ARGV[3].nil? ? 8 : ARGV[3]

# lets work in debug mode
Cdo.debug = true

# create a queue with a predifined number of workers
jq = JobQueue.new(nWorkers)

# split the input file wrt to variable names,codes,levels,grids,timesteps,...
splitTag = "ifs2icon_skel_split_"
#Cdo.splitcode(:in => iFile, :out => splitTag,:options => '-f nc')
Cdo.splitname(:in => iFile, :out => splitTag,:options => '-f nc')

# collect Files form the split
files = Dir.glob("#{splitTag}*.nc")

# remap variables in parallel
files.each {|file|
jq.push {
basename = file[0..-(File.extname(file).size+1)]
Cdo.remap(targetGridFile,targetGridweightsFile,
:in => file,
:out => "remapped_#{basename}.nc")
}
}
jq.run

# Merge all the results together
Cdo.merge(:in => Dir.glob("remapped_*.nc").join(" "),:out => 'mergedResults.nc')
(1-1/4)