! bn_hovmuller_overlays.jnl
! Previously a time series plot overlaid oon a Hovmuller plot did not 
! work unless the time axis of the original data had units of hours.
! See ticket 2344

! 1/6/2016 ACM
! acm* 3/17 check the URL with TEST_OPENDAP befor trying to open it.

! run this in the gif benchmarks.


def view/xlim=0,.333/ylim=.5,1    ul6
def view/xlim=.333,.666/ylim=.5,1 um6
def view/xlim=.666,1/ylim=.5,1    ur6
def view/xlim=0,.333/ylim=0,.5    ll6
def view/xlim=.333,1/ylim=0,.5    lr6

! The example from the FAQ, "Overlaying a time series on a 2D plot"
set view ul6

! Define a 2D field in YT with a time axis in units of DAYS
DEFINE AXIS/T="1-JAN-1980":"1-JAN-1990":5/UNITS=DAYS tdays
DEFINE AXIS/Y=0:40N:2/UNITS=DEGREES yax

LET/TITLE=XY my_var = 10*cos(T[gt=tdays]/2000)*EXP((-1)*y[gy=yax]/20)

! make a Hovmoller plot

SHADE my_var

! This did not work previously.  Needed to re-define the axis in units of hours
PLOT/OVER my_var[Y=@loc:-4]


! XT variable
set view um6

DEFINE AXIS/X=0:40E:1/UNITS=DEGREES xax
LET/TITLE="XT" my_var = 10*cos(T[gt=tdays]/20)*EXP((-1)*x[gx=xax]/20)
SHADE/t=1-jan-1987:1-jan-1989 my_var
PLOT/OVER/TRANS/THICK my_var[x=@loc:-4]


! Irregular time axis
set view ur6

DEFINE AXIS/T0=1-jan-2001/UNITS=DAYS tdays = {1,2,4,5,6,8,9,10,12,30,35,41,42,44,45,46,48,49,50,58}
DEFINE AXIS/Y=0:40N:2/UNITS=DEGREES yax
LET my_var = 10*cos(T[gt=tdays])*EXP((-1)*y[gy=yax]/8)

FILL/title="irregular t" my_var
PLOT/OVER/thick/y=8 my_var+10


! Like the dataset example from the FAQ
set view ll6

IF `test_opendap("http://ferret.pmel.noaa.gov/pmel/thredds/dodsC/data/PMEL/COADS/coads_sst.cdf") EQ 0` THEN
   use "http://ferret.pmel.noaa.gov/pmel/thredds/dodsC/data/PMEL/COADS/coads_sst.cdf"
   set region/x=40w/y=10n:60n/t=15-jan-1982:15-dec-1983
   shade sst
   plot/over/thick/TITLE="at 20"  sst[y=@LOC:20]
ENDIF

can data/all
can region

! vector plots with a time series
set view lr6

IF `test_opendap("http://ferret.pmel.noaa.gov/pmel/thredds/dodsC/data/PMEL/COADS/coads_uwnd.cdf") EQ 0 AND\
 test_opendap("http://ferret.pmel.noaa.gov/pmel/thredds/dodsC/data/PMEL/COADS/coads_uwnd.cdf") EQ 0` THEN
   use "http://ferret.pmel.noaa.gov/pmel/thredds/dodsC/data/PMEL/COADS/coads_uwnd.cdf"
   use "http://ferret.pmel.noaa.gov/pmel/thredds/dodsC/data/PMEL/COADS/coads_vwnd.cdf"

   vec/x=0/y=-10:10/t=1-jan-1980:1-jan-1990 uwnd[d=1], vwnd[d=2]

   let wspd = (uwnd[d=1]*uwnd[d=1] + vwnd[d=2]*vwnd[d=2])^0.5
   plot/over/color=red/thick/x=0/t=1-jan-1980:1-jan-1990 wspd[y=-10:10@ave]

   FRAME/FILE=bn_hovmuller_overlays.gif
ENDIF
