#! /bin/sh
#########################################################################
#  This script is part of the data assimilation suite. It processes a 
#  bias removal of rough data using good data. The data is assumed to be
#  in standard scalar [box.txt] format.
#
# Usage: ofs_bias.sh arg1 arg2 arg3                         
#  arg1  filename of data input (good data)                 
#  arg2  filename of data input (rough data)                
#  arg3  filename of data output                            
#
#
#  Main inputs
#  Files described as arg1 and arg2 above.
#  IDM,JDM   domain size
# 
#  Main output
#  File describe as arg3 above.
#  See also numerical parameters in the input file bias_fld_H.in.
#
# History:                                                  
#    06-16-2005  Dan Iredell                                
#########################################################################

echo "*** Started script $0"

goodinfile=$1
roughinfile=$2
outfile=$3

echo 'srtdate is ' $srtdate

#1  create bias_fld_H.in

echo "${IDM} ${JDM}        NCEP 1/12 ${srtdate}" > bias_fld_H.in
echo "5.0   w_r relative weight of gradient and misfit">> bias_fld_H.in
echo "0      passes number of passes through the smoother">> bias_fld_H.in
echo "400    nin_min  minimum no. of collocated GOOD and ROUGH values">> bias_fld_H.in
echo "0.6    maxdifqc">> bias_fld_H.in
echo "0.3    maxdiffld">> bias_fld_H.in
ngood=`cat ${goodinfile} | wc -l`
nrough=`cat ${roughinfile} | wc -l`
echo "${ngood}  no of records in GOOD">> bias_fld_H.in
echo "${nrough}  no of records in ROUGH">> bias_fld_H.in

#2     filter data

echo 	 Running bias for date $cdate
export pgm=ofs_bias_fld_H
. prep_step

echo ${FIXofs}/${RUN}_${modID}.${gridlabel}${mask}.dat

export XLFRTEOPTS="unit_vars=yes"
export XLFUNIT_10=${FIXofs}/${RUN}_${modID}.${gridlabel}${mask}.dat
export XLFUNIT_15=${goodinfile}
export XLFUNIT_16=${roughinfile}
export XLFUNIT_111=good_fld_c.txt
export XLFUNIT_112=rough_fld.txt
export XLFUNIT_114=coarse_all_flds.txt
export XLFUNIT_115=bias_fld_f.txt
export XLFUNIT_90=${outfile}

startmsg

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


echo "*** Finished script $0"

