\cancel mode verify
! stick_vectors_key.jnl
! 4/94
! 4/95 - instructions on how to use "PLOTV" and angle/increment arguments
! 7/01 *acm* update /ylimits to /vlimits
! 9/05 *acm* version that makes a key with a standard stick vector at the 
!            bottom instead of labelling the vertical axis with units.

! Description: Make a stick vector plot of a line of U,V values

! Usage:

!    GO stick_vectors_key PLOT/[quals] U V [angle] [increment]
! 1 command	   - PLOT with optional /OVERLAY, /TITLE, /NOLAB
!		   Note: other qualifiers will not function properly (see note)
! 2 U              - expression for the U component
! 3 V              - expression for the V component
! 4 angle          - rotation offset angle of vectors (default=0.0)
! 5 increment      - plot every Nth vector (default=1)

! We must be in a viewport!

! example:
!	yes? SET WINDOW/ASPECT=.4/SIZE=.5    ! long and skinny looks right
!	yes? SET DATA  monthly_navy_winds
!	yes? SET REGION/T=16-JAN-1985:16-JAN-1990/X=180/Y=0
!       yes? SET VIEW full
!	yes? GO stick_vectors_key plot uwnd vwnd
!  or
!	yes? GO stick_vectors_key plot/title=test/line=2/vlimits=-5:5:1 uwnd vwnd


! 4/95 -- alternative approach using PLOTV
! The approach below uses the FERRET command PLOT to load data as 2 variables
! U and V into PLOT+.  Then it uses "PPL PLOTUV" to perform the plot.
! An alternative approach is to use the FERRET "PLOT/VS" command to load the
! data into PLOT+ as "X" and "Y".  Then use "PPL XAXIS" and "PPL YAXIS" to
! eliminate the incorrect axis limits for the stick plot and use PPL PLOTV
! to draw the plot.  The X axis will be the numbers 1 ... N


! check for required filename and haf_inch_value and valid style
QUERY/IGNORE $1%<Usage: GO stick_vectors_key "VECTOR"/[QUALS] U V half_inch_value ["clock"] ["stick"]%
QUERY/IGNORE $2%<Usage: GO stick_vectors_key "VECTOR"/[QUALS] U V half_inch_value ["clock"] ["stick"]%
QUERY/IGNORE $3%<Usage: GO stick_vectors_key "VECTOR"/[QUALS] U V half_inch_value ["clock"] ["stick"]%

! set up the PLOT+ as if for a 2-line plot
$1/SET_UP $2, $3
ppl axatic,,1
ppl axlabp,,0


! ... but display it with the PLOTUV command
PPL PLOTUV $4"0" $5"1"

! Make the key: a single stick vector of a standard length: half the 
! y-axis length on the stick plot

! Get the size of the vector, equivalent to a quarter of the size of the
! vertical axis which is determined automatically when making the plotuv plot.

let sticklab = `(($yaxis_max) - ($yaxis_min))/4`  ! for label
let sticklen = `($ppl$ylen)/4/($VP_WIDTH)/($VP_SCALE)`
let xstart = ($ppl$xorg)/($VP_WIDTH)/($VP_SCALE)

! Define a viewport in which to put the key.
let vht = ($ppl$yorg)/($VP_WIDTH)/($VP_SCALE)
def view/axes/xlim=0.:1./ylim=0:`vht` keyview

! Make a dummy plot in the viewport to set the scaling, then draw and 
! label the stick.

set view keyview
plot/i=1:10/hlim=0:1/vlim=0:1/noax/nolab 10*i
let ypos = 0.8
plot/over/vs/LINE/color=black/noax/nolab {`xstart`, `xstart+sticklen`}, {`ypos`, `ypos`}
let keysize = 0.14

LET unit_lab = "`$2,return=units`"
LABEL `xstart+sticklen+keysize/10`,`ypos - keysize/3`, -1, 0, `keysize`, "`sticklab` `unit_lab`"

set mode/last verify


set mode/last verify

