\cancel mode verify
! box.jnl - draw a box using the indicated corners
! 8/94
! 1/03 bug fix: with v5.5 Ferret, possible negative numbers in arguments 
!               need to be in parentheses within the IF THEN statements
! 2/18 Further refinements to work correctly with negative arguments.
!      Modernize the use of longitude coordinates and line colors, styles.

! Description: Overlay a colored box outline given the corner coordinates

! usage:  GO box xlo xhi ylo yhi [line_style]
!         Argument 5 may be a pen number, a defined color name, or a combination
!         of color with line style, such as red/thick. If a combination is used, 
!         it must consist of a color name or number followed by any other arguments

! examples
!      GO box -180 -120 -45 45 2		  ! red box
!      GO box  300  345  25 45 black/thick/dash   ! black box drawn with thick, dashed lines

! Notes:
!  1) use  GO line_samples    to view the first 6 pen numbers

! first 4 arguments are required
query/ignore $1%<Usage: GO box xlo xhi ylo yhi [pen_number]%
query/ignore $2%<Usage: GO box xlo xhi ylo yhi [pen_number]%
query/ignore $3%<Usage: GO box xlo xhi ylo yhi [pen_number]%
query/ignore $4%<Usage: GO box xlo xhi ylo yhi [pen_number]%

! Define coordinates of the box.  Allow for any of these to be negative.
! Give units to the x coordinates, so moduloing will be done, (This is
! harmless if the x axis of the underlying plot is not longitude)

LET/QUIET/UNITS=degrees_east XBOX_CORNERS = IF I LE 2 THEN (($1)) ELSE (XBOX_CORNER2)
LET/QUIET/UNITS=degrees_east XBOX_CORNER2 = IF I LE 4 THEN (($2)) ELSE (($1))
LET/QUIET YBOX_CORNERS = IF I EQ 1 THEN (($4)) ELSE (YBOX_CORNER2)
LET/QUIET YBOX_CORNER2 = IF I LE 3 THEN (($3)) ELSE (($4))

! Overlay the box
PLOT/VS/NOLAB/OVER/LINE/color=($5%black%)/I=1:5 XBOX_CORNERS, YBOX_CORNERS

set mode/last verify
