#!/bin/csh -fv

###----------------------------------------------------------------------------
###  cp'd from /cgd/oce/yeager/POP_GRIDS/Initial_Conditions/mk_sfwf_data.csh
###  used in the computation of /fs/cgd/csm/inputdata/ocn/pop/gx3v5/forcing/sfwf_20040517.ieeer8
###----------------------------------------------------------------------------

set echo
set verbose

# This script computes the initia Temp and Salt condition from Levitus
#     for a new grid: 

#1) Set up these parameters to run:
  set user = yeager
  set GRID = gx3v5
  set GRIDDIR = /fis/cgd/cseg/csm/inputdata/ocn/pop/gx3v5/grid
  set TAGDIR = /fis/cgd/cseg/csm/collections/ccsm3_0_beta22/models/ocn/pop/input_templates

#2) cd to a temporary directory; get needed files etc.
  if !(-d $GRIDDIR)  mkdir -p $GRIDDIR
  set DIR = /ptmp/$user/$GRID
  if !(-d $DIR)  mkdir -p $DIR
  cd $DIR 

#3) Get POLES 1x1 data off Mass Store:
# msread PHC2_TEMP.nc /HECHT/POLES/PHC2_TEMP.nc
# msread PHC2_SALT.nc /HECHT/POLES/PHC2_SALT.nc

#4)Make namelist :
cat > PHC2_${GRID}_nml << EOFINPUT1
&regrid_nml
  src_file = '/ptmp/yeager/PHC2_salx.nc'
  src_var  = 'SALT'
  dst_imt  = 100
  dst_jmt  = 116
  dst_km   =  1
  dst_horiz_grid_file = '${GRIDDIR}/horiz_grid_20030806.ieeer8'
  dst_vert_grid_file  = '${TAGDIR}/gx3v5_vert_grid'
  dst_topography_file = '${GRIDDIR}/topography_20040323.ieeei4'
  dst_region_mask_filename = '${GRIDDIR}/region_mask_20040220.ieeei4'
  dst_file     = 'PHC2_salx_${GRID}.nc'
  dst_lclobber = .true.
/
EOFINPUT1

#5)Run Program and cp to GRIDDIR:
  scp flagstaff.cgd:/fs/cgd/data0/klindsay/POP_tools/regrid/regrid .    
  regrid < PHC2_${GRID}_nml 

exit(0)

