#!/bin/sh
set -e
# Computes the mean for COSP fields that need to be divided to by occurence counter and masked locations where the counter is zero

if [ $# -ne 4 ] ; then
  echo "Error in $0: invalid number of arguments $#"
  exit 1
fi
pfx=$1
inp1=$2 # Numerator
inp2=$3 # Denominator
out=$4

access inp1 ${pfx}_${inp1}
access inp2 ${pfx}_${inp2}

div inp1 inp2 temp
echo "C* FMSKPLT        -1 NEXT   GT      0.00    1     1.E38    1" | ccc fmskplt temp ${pfx}_${out} inp2

release inp1 inp2
rm temp