-- Create PrecipitationType and PrecipitationForm from Potential parameter version
-- Only for smartmet editor data
-- partio 2018-02-16

local ppf = luatool:Fetch(current_time, level(HPLevelType.kHeight, 0), param("POTPRECF-N"))
local ppt = luatool:Fetch(current_time, level(HPLevelType.kHeight, 0), param("POTPRECT-N"))
local rrr = luatool:Fetch(current_time, level(HPLevelType.kHeight, 0), param("RRR-KGM2"))

if not ppf or not ppt or not rrr then
  return
end

local i = 0
local pf = {}
local pt = {}

local MISS = missing

for i=1, #ppf do

  local _pf = MISS
  local _pt = MISS

  if rrr[i] > 0 then
    _pf = ppf[i]
    _pt = ppt[i]
  end 

  pf[i] = _pf
  pt[i] = _pt
end

-- using param PRECFORM2-N because that has mapping ready in radon
result:SetValues(pf)
result:SetParam(param("PRECFORM2-N"))
luatool:WriteToFile(result)

result:SetValues(pt)
result:SetParam(param("PRECTYPE-N"))
luatool:WriteToFile(result)

Add script to create precipitation type & form from potential versions
Add script to create precipitation type & form from potential versions

This is done by masking those gridpoints where precipitation sum is zero
