!#/bin/csh
set echo
set time=1
#
# --- form interpolated subregion archive files, GLBa0.08 to WPAb0.08.
#
# --- script includes logic to reduce the number of layers,
# --- but it is inactivated here by setting L to "".
#
# --- ALL/bin/hycom_ij2lonlat can be used to find co-located points
# ---  on the two grids.  Since subregion p(1,1) must be on the
# ---  original grid, this is usually the point to reference.
#
if ($#argv != 3) then
   echo "Usage: $0 PDY CDIR FILETYPE"
   exit -2
endif
set cPDY=$1
set cDIR=$2
set cAFILE=$3
setenv D    ${cDIR}
setenv R    ${DATA}/nest
setenv AFT    ${cAFILE}
#
#
if (-z ${R}) then
mkdir -p ${R}
endif
cd ${R}
#
#
# --- single model segment, potentially across two calendar years.
# --- configured for  1-day surface and  1-day 3-d archives.
#
setenv iidm 921 
setenv jjdm 697
setenv irefi 761
setenv jrefi 1699
setenv YD `${utilscript}/date2jday.sh ${cPDY} | cut -c5-` 
setenv YR `echo ${cPDY} | cut -c1-4` 

#
  ln -s -f  ${FIXofs}/rtofs_glo.navy_0.08.regional.grid.a regional.grid.a
  ln -s -f  ${FIXofs}/rtofs_glo.navy_0.08.regional.grid.b regional.grid.b

# hCk $EXECofs/${RUN}_${modID}_isubregion >>$pgmout 2>errfile <<E-o-D
$EXECofs/${RUN}_${modID}_isubregion <<E-o-D
${D}/rtofs_glo.t00z.${AFT}.archv.b
${FIXofs}/rtofs_glo.navy_0.08.regional.depth.b
${R}/archv.${YR}_${YD}_${cyc}.b
${FIXofs}/${RUN}_${modID}.regional.depth.b
GLBa0.08 interpolated to ${modID}
${iidm}	'idm   ' = longitudinal array size
${jjdm}	'jdm   ' = latitudinal  array size
${irefi}	'irefi ' = longitudinal input  reference location
${jrefi}	'jrefi ' = latitudinal  input  reference location
   1	  'irefo ' = longitudinal output reference location
   1	  'jrefo ' = latitudinal  output reference location
   1	  'ijgrd ' = integer scale factor between input and output grids
   1	  'iceflg' = ice in output archive flag (0=none,1=energy loan model)
   0	  'smooth' = smooth interface depths    (0=F,1=T)
E-o-D
export err=$?; err_chk
#
unlink regional.grid.a
unlink regional.grid.b
#
