#!/bin/sh -e

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

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

# cut the first record from the current year
release inp 
access inp ${pfx}_${inp}
echo "C*RCOPY            2      2920" | ccc rcopy inp inps
release inp 

# paste the first record from the next year
year=${pfx%_3h}
year=${year##*_}
year=${year:0:4}
nxyr=$((year+1))
nfx=$(echo $pfx| sed -e "s/${year}_${year}/${nxyr}_${nxyr}/" -e "s/${year}01_${year}12/${nxyr}01_${nxyr}12/")

access inp ${nfx}_${inp}
echo "C*RCOPY            1         1" | ccc rcopy inp inp1
cat inp1 >> inps

#change units into Pa
echo "                100." | ccc xlin inps ${pfx}_${out}

release inp inp1 inps
