#!/bin/sh
###############################################################################
#                                                                             #
# This script is called by ofs_ctd_assim.sh                                   #
#                                                                             #
#  ofs_z2layer.sh : obtains profiles in model layers from profiles in z levels#
#                                                                             #
#   exported in:                                                              #
#   ctdfile                                                                   #
#   numobsfile                                                                #
#   outfile                                                                   #
#   monitorfile                                                               #
#                                                                             #
#  also exported in                                                           #
#    DATA : working directory                                                 #
#    PARMofs and EXECofs                                                      #
#                                                                             #
###############################################################################

set -x

echo "*** Started script $0"

echo 'ctd profile file is                            ' ${ctdfile}
echo 'file with number of obs in ctd profile file is ' ${numobsctdfile}
echo 'outfile is                                     ' ${z_outfile}
echo 'monitor file is                                ' ${z_monitorfile}

cp ${PARMofs}/${RUN}_${modID}.z2layer.in z2layer.in
# z2layer_f.f sets iuctd=20 and iusig=80
# iuctd is the input profile file
# iuctd+1 is the file with the number of profiles
# iusig is the output file
# iuctd+2 is the file with both the profiles and layers

export pgm=ofs_z2layer_f
. prep_step

export XLFRTEOPTS="unit_vars=yes"

export XLFUNIT_20=$ctdfile
export XLFUNIT_21=$numobsctdfile
export XLFUNIT_22=$z_monitorfile
export XLFUNIT_80=$z_outfile

startmsg

${EXECofs}/ofs_z2layer_f  < z2layer.in  >> $pgmout 2> errfile
export err=$?; err_chk

echo "*** Finished script $0"


