#! /bin/sh
#########################################################################
#  This script is part of the data assimilation suite. It processes 
#              scalar observations as follows:
#              a)observation event is mapped to grid location and model time
#              b)mean and std from climatology is attached to the data
#              c)quality control flags are enabled
#
# Usage: ofs_boxqc.sh arg1 arg2 arg3                                
#  arg1  data type { sst ctd ssh ]                                  
#  arg2  filename of data input                                     
#  arg3  filename of data output                                    
#                                                                   
#  Main inputs
#  See arguments above
#
#  macros:
#  srtdate       central date
#  climo_month   month to employed from climatological files
#
#                                                                   
#  Main output
#  arg3: file with extended information about observations. This is a 
#        box-style file
#
# History:                                                          
#    06-16-2005  Dan Iredell                                        
#########################################################################

echo "*** Started script $0"

platform=$1
infile=$2
outfile=$3
# field is first 3 chars of platform capitalized
field=`echo $platform | cut -c1-3 | tr '[a-z]' '[A-Z]'`

climo_month=`echo ${srtdate} | cut -c5-6`

echo 'srtdate is ' $srtdate
echo 'field is ' $field
echo 'climo_month is ' $climo_month

#1.b  create boxin.in
it0=`echo $t0 | cut -d. -f1`

echo "${platform}" > boxin.in
echo "${IDM} ${JDM}  $it0      NCEP 1/12 ${srtdate}" >> boxin.in

#2     filter data
echo 	 Running boxin for $platform  $cdate
echo ${gridlabel} '   ' ${IDM} ${JDM} '   ' ${climo_month}

export pgm=ofs_boxin
. prep_step

export XLFRTEOPTS="unit_vars=yes"
export XLFUNIT_10=$infile
export XLFUNIT_12=${PARMofs}/${RUN}_${modID}.platform.dat
export XLFUNIT_72=${FIXofs}/${RUN}_${modID}.${gridlabel}${mask}.dat
export XLFUNIT_73=${FIXofs}/${RUN}_${modID}.${gridlabel}grid.dat
export XLFUNIT_74=${FIXofs}/${RUN}_${modID}.${gridlabel}mean${field}${climo_month}.bin
export XLFUNIT_75=${FIXofs}/${RUN}_${modID}.${gridlabel}sdev${field}${climo_month}.bin
export XLFUNIT_76=${FIXofs}/${RUN}_${modID}.Atlantic.dat 
export XLFUNIT_80=$outfile

startmsg

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


echo "*** Finished script $0"

