#!/usr/bin/env bash
set -x
input="$1"
applyMask="-mul -gtc,-10 ${input}"

# good for data without missing values
cdo -diffv [ -fldmean ${input} -div -fldsum -mul [ ${input} -gridarea ${input} ] [ -fldsum -gridarea ${input} ] ]

# valid for fields that contain missing values
cdo -diffv  -fldmean ${input} -div -fldsum -mul  ${input} ${applyMask} -gridarea ${input}  -fldsum ${applyMask} -gridarea ${input}
