#! /bin/sh
#########################################################################
#  This script is part of the HYCOM model run and it resets the mean
#  values of the lowfrequendy data at the boundaries (extermal mode)
#
# Usage: ofs_lowfreq_mean
#
#  Main inputs
#  
#  lowfreq.input
# 
#  Main output
#  lowfreq.input  
#  lowfreq.input_old same as input
#
# History:                                                  
#    06-16-2005  Dan Iredell                                
#########################################################################

echo "*** Started script $0"

echo 'srtdate is ' $PDY

#1  setup input to the program ofs_lowfreq_mean

month=`echo $PDY|cut -c5-6 `
day=`echo $PDY|cut -c7-8 `
in_unit=12
out_unit=60

# find number of ports
npline=`grep nports $PARMofs/ofs_${modID}.ports.input`
nports=`echo $npline | cut -d\' -f1`

echo " $month  $day " > lowfreq_mean.in
echo " ${nports}  ${in_unit}  ${out_unit}  number of ports, input and output logical units">> lowfreq_mean.in

i=1
while [ $i -le $nports ]
do
  echo " $i           " >> lowfreq_mean.in
  let i=i+1
done

#  Note the order of the ports is that on ports.input
#  the range of ports in lowfreq.input is coded in the program ofs_lowfreq_mean

#2     shift mean values

echo 	"  Running shift of mean sea level at boundaries  for date $PDY "
export pgm=ofs_lowfreq_mean
. prep_step

cp lowfreq.input lowfreq.input_old
rm -f lowfreq.input

export XLFRTEOPTS="unit_vars=yes"
export XLFUNIT_12=lowfreq.input_old
export XLFUNIT_60=lowfreq.input
export XLFUNIT_20=lowfreq_mean.txt

startmsg

$EXECofs/$pgm  < lowfreq_mean.in >> $pgmout 2> errfile
export err=$?; err_chk


echo "*** Finished script $0"

