#
set echo
#
# --- form subregion bathymetry file, GLBa0.08 to WPAb0.08.
#
# --- 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.
# --- In this case:
# ---   hycom_ij2lonlat 1 1 ~/hycom/IASa0.50/topo/regional.grid.a
# ---    97.000W   3.997N
# ---   hycom_ij2lonlat 1 13 ~/hycom/ATLa2.00/topo/regional.grid.a
# ---    97.000W   3.997N
#

if ($#argv != 2) then
   echo "Usage: $0 CDIR FILETYPE"
   exit -2
endif

set cDIR=$1
set cFFILE=$2

setenv D ${cDIR}
setenv R ${DATA}
setenv FFT ${cFFILE}

#
if (-z ${R}) then
mkdir -p ${R}
endif
cd ${R}
#
foreach f (airtmp precip radflx shwflx surtmp tauewd taunwd vapmix wndspd )
setenv fname ${D}/rtofs_glo.${FFT}.t00z.forcing.${f}
#touch   ${R}/forcing.${f}.[a,b]
#/bin/rm ${R}/forcing.${f}.[a,b]
setenv idm 921 
setenv jdm 697 
setenv irefi 761
setenv jrefi 1699
$EXECofs/${RUN}_${modID}_subset ${fname}.a 4500 3298 $irefi $jrefi $idm $jdm $R/forcing.${f}.a | awk '{printf ( "%16.7E%16.7E\n", $4, $5)}' > temp2.b

tail +6 ${fname}.b | cut -c1-41  > temp1.b
head -5 ${fname}.b | sed -e  "s/4500 3298 tripolar/ $idm $jdm subset of GLB/" > ${R}/forcing.${f}.b
setenv nl ` wc temp1.b | awk '{print $1 + 5}'`
setenv nl ` wc temp1.b | awk '{print $1 }'`
head  -${nl} temp2.b > temp3.b
paste -d ' ' temp1.b temp3.b >>  ${R}/forcing.${f}.b
rm -f temp1.b temp2.b temp3.b
end
