\CANCEL MODE VERIFY
! bar_chart.jnl   *sh* 11/93

! Description: Make a bar chart using color fill (not suitable for Z axis)

! this routine will take a simple 1D line of data and represent it as a
! bar chart from FERRET

! Note:  The line of data may be a line in X, Y, or T but not Z. The Z
! location of the data to be plotted (if relevant) must be unambiguously
! given as a part of the expression.  A simple modification of this routine
! could make a Z-line plottable (at the sacrifice of one other axis).

! usage: GO bar_chart expression lo_limit hi_limit [color]
!	"color" must be the name of a .spk file in the $FER_PALETTE list

! example 1 (abstract):
!	yes? GO bar_chart sin(X[i=1:30]/6) -1 1 .05
! example 2 (time series of sst):
!	yes? SET DATA gt01mncoads
!	yes? SET REGION/X=180/Y=0/t=1-jan-1980:1-jan-1990
!	yes? GO bar_chart sst 27 31 red

! Had the variable in the data set been 4D temperature ("temp") instead of SST
! the correct command would have been "GO bar_chart temp[Z=0] 27 31"
! The command argument "delta" is the resolution of the vertical axis of the
! plot.

! capture the current region because Z limits will be modified

! check the arguments
QUERY/IGNORE $1"<usage: yes? GO bar_chart expression lo_limit hi_limit [color]"
QUERY/IGNORE $2"<usage: yes? GO bar_chart expression lo_limit hi_limit [color]"
QUERY/IGNORE $3"<usage: yes? GO bar_chart expression lo_limit hi_limit [color]"

! define a 2D grid for the display
DEFINE AXIS/Z=$2:$3/npoints=40 zbchart
DEFINE GRID/z=zbchart gbchart

! define a 2D field that has the desired bar chart shape
LET bchart_data = $1"<usage: GO bar_chart [lo] [hi] [delta]"
LET bchart = IF z[g=gbchart,Z=$2:$3] LT bchart_data THEN 0.0

! grab the title and units string as PLOT+ symbols
PLOT/SET $1
ppl set savetitl 'labtit'
ppl set saveylab 'laby'

! now to display it as a 2-D bar chart (color control not fully supported)
! palette defaults to gray.spk - other palettes are OK
shade/nokey/palette=$4"gray"/SET bchart
ppl TITLE @AC'savetitl'
ppl YLAB  @AS'saveylab'
ppl shade

! cleanup
!SET REGION save
!cancel region save
SET MODE/LAST VERIFY


