#!/bin/sh
set -e

USAGE='
Perturb slightly winds (VORT and DIV) in AGCM restart files.

USAGE

  pertrs rs_input.NNN [ rs_output[.MMM] ]

where

rs_input.NNN is AGCM rs restart file with edition number NNN.

If output restart file is not specified, the new restart file name will be
rs_input.NNP where NNP=NNN+1.
'

if [ $# -eq 0 -o $# -gt 2 ] ; then
  echo "$USAGE"
  exit
fi

inp=$1

dir=`dirname $inp`
base=`basename $inp`
pfx=`echo $base | sed -e 's/\(.*\)\.\([0-9][0-9][0-9]\)/\1/'`
ed=`echo $base | sed -e 's/\(.*\)\.\([0-9][0-9][0-9]\)/\2/'`

echo inp=$inp
echo dir=$dir base=$base pfx=$pfx ed=$ed

echo "C*PERTURB          1    1.E-15    1" | ccc perturb_winds $inp $pfx

save $pfx $pfx
release $pfx .ccc_cards
