#!/bin/sh
set -e
# Get the 1st level and multiply by 1E-6 -- DY, 2019-01-09.

if [ $# -ne 3 ] ; then
  echo "Error in $0: invalid number of arguments $#"
  exit 1
fi

pfx=$1
inp=$2
out=$3

# Get CDO / TEMPORARY!
export PATH=/fs/ssm/hpco/exp/mib002/anaconda/anaconda-4.4.0/anaconda_4.4.0_ubuntu-14.04-amd64-64/envs/cdo-1.9.0/bin:$PATH

release inp
access  inp ${pfx}_${inp}.nc

# Get the 1st level
ncks -F -d deptht,1,1 inp out1

# Remove deptht
ncwa -O -a deptht out1 out2

# multiply by 1e-6
cdo mulc,1e-6 out2 ${pfx}_${out}

release inp
rm -f out1 out2
