#!/bin/csh -f

# Incremental S4DVAR job script:
#
# This script NEEDS to be run before any run:
#
#   (1) It copies a new clean nonlinear model initial conditions
#       file. The nonlinear model is initialized from the
#       background or reference state.
#   (2) It copies a new clean tangent linear model intial conditions
#       file. The tangent linear model is started from rest. That is
#       all the state variables are zero.
#   (3) Create 4DVAR input script from a template and specify the
#       the background-error standard deviation, normalization, and
#       observation files.
#

# Set working directory path.

  set Dir=${OCEANHOME}/toms/adjoint/Test/gyre3d/500
# set Dir=${MOBYHOME}/Work/gyre3d/500

 cp -p ${Dir}/Data/gyre3d_bck.nc gyre3d_ini.nc

# Copy tangent linear model initial conditions file.

 cp -p ${Dir}/Data/gyre3d_ini_zero.nc gyre3d_itl.nc

# Copy representer model initial conditions file, same as nonlinear model.

 cp -p gyre3d_ini.nc gyre3d_irp.nc

# Set background-error covariance standard deviations file.

#set STDname=../Data/gyre3d_std_constant.nc     # constant variance
 set STDname=../Data/gyre3d_std.nc              # variance at each point

# Set background-error covariance normalization factor file

 set NRMname=../Data/gyre3d_nrm_100k100i.nc         # 100km, 100m implicit

# Set observations file.

set OBSname=gyre3d_zuvTS_obs.nc

# Get a clean copy of the observation file.  This is really
# important since this file is modified to add nonlinear
# model and tangent linear model at observation points. It
# also add the observation operator Hmat.

 cp -p ${Dir}/OBS/$OBSname .

# Modify S4DVAR template input script and specify above files.

 set W4DVAR=w4dvar.in
 if (-e $W4DVAR) then
   /bin/rm $W4DVAR
 endif
 cp s4dvar.in $W4DVAR

 substitute $W4DVAR ocean_std.nc $STDname
 substitute $W4DVAR ocean_nrm.nc $NRMname
 substitute $W4DVAR ocean_obs.nc $OBSname
 substitute $IS4DVAR ocean_mod.nc gyre3d_mod.nc
