#!/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

# Copy nonlinear model initial conditions file.

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

# Copy tangent linear model initial conditions file.

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

# Set background-error covariance standard deviations file.

set STDname=../Data/gyre3d_std.nc

# 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 ../OBS/$OBSname .

# Modify S4DVAR template input script and specify above files.

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

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