#! /bin/csh -f

source $CASEROOT/env_conf || exit -1
source $CASEROOT/env_run  || exit -1
source $CASEROOT/env_mach.$MACH  || exit -1
source $CASEROOT/env_pes.$MACH  || exit -1

 #******************************************************************#
 # If the user changes any input datasets - be sure to give it a    #
 # unique filename. Do not duplicate any existing input files       #
 #******************************************************************#

# started as a hybrid run

set runtype = hybrid
if ($CONTINUE_RUN == 'TRUE') set runtype = 'continue'

set exedir = $EXEROOT/cpl
cd $exedir

set rest_bfile    = null
set map_a2of_file = map_T42_to_gx1v3_aave_da_010709.nc
set map_a2os_file = map_T42_to_gx1v3_bilin_da_010710.nc
set map_o2af_file = map_gx1v3_to_T42_aave_da_010709.nc
set map_r2o_file  = map_r05_to_gx1v3_roff_smooth_010718.nc

$UTILROOT/Tools/ccsm_getinput cpl/cpl6/$map_a2of_file $map_a2of_file || exit 1
$UTILROOT/Tools/ccsm_getinput cpl/cpl6/$map_a2os_file $map_a2os_file || exit 1
$UTILROOT/Tools/ccsm_getinput cpl/cpl6/$map_o2af_file $map_o2af_file || exit 1
$UTILROOT/Tools/ccsm_getinput cpl/cpl6/$map_r2o_file  $map_r2o_file  || exit 1

if !($NTASKS_CPL > 0) then
  echo "NTASKS_CPL must be > 0, please correct in env_pes and reconfigure"
  exit -1
endif
if !($NTHRDS_CPL == 1) then
  echo "NTHRDS_CPL must be 1, please correct in env_pes and reconfigure"
  exit -1
endif

#--- set run type
if ($runtype == 'startup' ) set run_type = initial
if ($runtype == 'hybrid'  ) set run_type = initial
if ($runtype == 'branch'  ) set run_type = branch
if ($runtype == 'continue') set run_type = continue

cat >! cpl.nml << EOF
  &inparm
  case_name     = '$CASE '
  case_desc     = '$CASE $CASESTR '
  start_type    = "$run_type"
  start_date    =  05010101
  start_pfile   = 'rpointer.cpl '
  start_bfile   = "$rest_bfile"
  stop_option   = '$STOP_OPTION'
  stop_n        =  $STOP_N
  rest_option   = '$REST_OPTION'
  rest_n        =  $REST_N
  diag_option   = '$DIAG_OPTION'
  diag_n        =  $DIAG_N
  hist_option   = '$HIST_OPTION'
  hist_n        =  $HIST_N
  hist_64bit    =  $HIST_64BIT
  avhist_option = "$AVHIST_OPTION"
  avhist_n      =  $AVHIST_N
  map_a2of_fn   = "$map_a2of_file"
  map_a2os_fn   = "$map_a2os_file"
  map_o2af_fn   = "$map_o2af_file"
  map_r2o_fn    = "$map_r2o_file"
  orb_year      =  1990
  flx_epbal     = 'off'
  flx_albav     = .false.
  info_dbug     =  $INFO_DBUG
  bfbflag       = .false.
  /
EOF

