#!/bin/csh -x
#PBS -N XXX
#PBS -j oe
#PBS -o XXX.log
#PBS -W umask=027
#PBS -l application=home-grown
#PBS -l walltime=0:20:00
#PBS -l select=1:ncpus=44:mpiprocs=1
#PBS -A ONRDC10855122 
#PBS -q debug
#
set echo
set time=1
date
#
# --- extract 2-d field EKE from a single HYCOM archive file.
# --- output is Netcdf files
# --- this is can be run on 1 proc/ on login node
#
# --- R is region name.
# --- E is expt number.
# --- X is decimal expt number.
# --- T is topography number.
# --- Y is year
# --- P is month
# --- J is julian day
#
setenv X 03.9 
setenv R GLBb0.08
setenv EX ~/HYCOM-examples/${R}/expt_${X}
setenv E 039
setenv Y 1993_2018

#
cd /p/work1/$user/HYCOM-examples/${R}/expt_${X}/data/
#
touch regional.depth.a regional.depth.b
if (-z regional.depth.a) then
  /bin/rm regional.depth.a
  /bin/ln -sf ~/HYCOM-examples/${R}/topo/regional.depth.a regional.depth.a
endif
if (-z regional.depth.b) then
  /bin/rm regional.depth.b
  /bin/ln -sf ~/HYCOM-examples/${R}/topo/regional.depth.b regional.depth.b
endif
#
touch regional.grid.a regional.grid.b
if (-z regional.grid.a) then
  /bin/rm regional.grid.a
  /bin/ln -sf ~/HYCOM-examples/${R}/topo/regional.grid.a .
endif
if (-z regional.grid.b) then
  /bin/rm regional.grid.b
  /bin/ln -sf ~/HYCOM-examples/${R}/topo/regional.grid.b .
endif

# --- domain
setenv IDM 4500
setenv JDM 3298
setenv K   36

# name of the SDA file
setenv A ${E}_archSDA.${Y}_10d
# directory of the SDA file
setenv D /p/work1/abozec/HYCOM-examples/GLBb0.08/expt_03.9/data/
#
# --- interpolate to 3-d z-levels from a single HYCOM archive file.
# --- z-levels, via linear interpolation.
#
# --- optional title and institution.
#
setenv CDF_TITLE        "HYCOM ${R}"
setenv CDF_INST         "Naval Research Laboratory"
#
foreach DD ( 0005 0700 1000 )
  setenv   CDF033  ${A}_eke_${DD}m.nc
  /bin/rm $CDF033
 ~wallcraf/HYCOM-tools/archive/src/archv2data3z <<E-o-D
${D}/${A}.a
NetCDF
 000    'iexpt ' = experiment number x10 (000=from archive file)
   0    'yrflag' = days in year flag (0=360J16,1=366J16,2=366J01,3-actual)
${IDM}  'idm   ' = longitudinal array size
${JDM}  'jdm   ' = latitudinal  array size
 ${K}   'kdm   ' = number of layers
  34.0  'thbase' = reference density (sigma units)
   0    'smooth' = smooth the layered fields (0=F,1=T)
   1    'iorign' = i-origin of plotted subregion
   1    'jorign' = j-origin of plotted subregion
   0    'idmp  ' = i-extent of plotted subregion (<=idm; 0 implies idm)
   0    'jdmp  ' = j-extent of plotted subregion (<=jdm; 0 implies jdm)
   1    'itype ' = interpolation type (0=sample,1=linear)
   1    'kz    ' = number of depths to sample
 ${DD}  'z     ' = sample depth  1
   0    'botio ' = bathymetry       I/O unit (0 no I/O)
   0    'mltio ' = mix.l.thk.       I/O unit (0 no I/O)
   0    'tempml' = temperature jump across mixed-layer
   0    'densml' =     density jump across mixed-layer
   0    'infio ' = intf. depth      I/O unit (0 no I/O, <0 label with layer #)
   0    'wviio ' = intf. w-velocity I/O unit (0 no I/O)
   0    'wvlio ' = w-velocity       I/O unit (0 no I/O)
   0    'uvlio ' = u-velocity       I/O unit (0 no I/O)
   0    'vvlio ' = v-velocity       I/O unit (0 no I/O)
   0    'splio ' = speed            I/O unit (0 no I/O)
   0    'temio ' = temperature      I/O unit (0 no I/O)
   0    'salio ' = salinity         I/O unit (0 no I/O)
   0    'tthio ' = density          I/O unit (0 no I/O)
  33    'keio  ' = EKE              I/O unit (0 no I/O)
E-o-D
  date
end
#
wait
date
