#!/bin/sh -x
set -e
# select 200hPa only from the input file.

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

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

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

# select the specific pressure level 
echo "SELECT.   STEPS         1 999999999    1 LEVS  200  200 NAME  ALL"|ccc select inp ${pfx}_${out}
var=`ggstat inp| egrep "GRID|ZONL"|head -1|cut -c25-28`
if [ $var = "GZ" -o $var = "PHI" ]; then
  echo "C*XLIN       9.80616        0.         1" | ccc xlin ${pfx}_${out} tmp; mv tmp ${pfx}_${out}
fi

release inp
