#!/bin/sh
###############################################################################
#                                                                             #
# This script creates the assimilation for OFS_atl model                      #
#                                                                             #
#  spread.sh : runs 2dvar to create:                                          #
#              input: from inova (ascii table)                                #
#              output                                                         #
#                  - residual vector (ascii table)                            #
#                  - anomaly fld     (binary)                                 #
#   exported in:                                                              #
#     fld [sst,ssh,ctd]                                                       #
#     srtdate                                                                 #
#     cyc                                                                     #
#     OBSFILE    data input filename                                          #
#     OBSFILE_OUT    data output filename                                     #
#     FLD_NAME       analysis filename                                        #
#     fac_unit       factor for correlation scale                             #
#     record_no      record format number                                     #
#                                                                             #
#                                                                             #
###############################################################################

set -x
echo "*** Started script $0"


# --------------------------------------------------------------------------- #
# 0.  Preparations
# 0.a Basic modes of operation

  echo ' '
  echo '                      *******************************'
  echo '                      *** SPREAD  SCRIPT          ***'
  echo '                      *******************************'
  echo ' '
  echo "Starting at : `date`"

# --------------------------------------------------------------------------- #
# 1.  Run spread
# 1.a  construct standard input file 

export num_obs=`cat ${OBSFILE}| wc -l`

/bin/rm -f ofs_spread.in
cat > ofs_spread.in <<EOF
${OBSFILE}
${OBSFILE_OUT}
${FLD_NAME}
${num_obs}
${fac_unit}
${record_no}
EOF

# 1.c  execute spread

# to run on physical CPU's
#export MEMORY_AFFINITY=MCM
#export TARGET_CPU_LIST=-1
#poe /usrx/local/mpi_trace/utils/launch.x $EXECofs/ofs_spread < ofs_spread.in -procs $NPROCS >> $pgmout 2>errfile 

poe $EXECofs/ofs_spread < ofs_spread.in >> $pgmout 2> errfile 

export err=$?; err_chk

echo "*** Finished script $0"
