* PLOT2.CMD  Plots bar charts for PLOT.CMD
*
STORE 0 TO OUTBND
STORE -1 TO OLDX
STORE -1 TO OLDY
GO TOP
DO WHILE .NOT. EOF
  IF .NOT. *
    STORE (&XVAR-MINX)/(MAXX-MINX) TO XFRAC
    STORE (&YVAR-MINY)/(MAXY-MINY) TO YFRAC
    STORE PLOT:LF+1+INT((XFRAC*(PLOT:RT-PLOT:LF-1))+.5) TO TEMPX
    STORE PLOT:BT-1-INT((YFRAC*(PLOT:BT-1))+.5) TO TEMPY
* check if point is in bounds
    IF TEMPX>PLOT:RT .OR. TEMPX<PLOT:LF .OR. TEMPY>PLOT:BT-1;
        .OR. TEMPY<1
      STORE OUTBND+1 TO OUTBND
    ELSE
* Point is in bounds, so plot bar
      STORE TEMPX TO XPOS
      STORE TEMPY TO YPOS
      @ YPOS,XPOS SAY CHR(17)
* Put in vert line
      STORE YPOS+1 TO TEMP
      DO WHILE TEMP<PLOT:BT
        @ TEMP,XPOS SAY CHR(1)
        STORE TEMP+1 TO TEMP
      ENDDO
* Horz line from last point
      IF OLDX<>-1
        STORE XPOS-OLDX TO DELX
        STORE OLDX+1 TO TEMP
        DO WHILE TEMP<XPOS
          @ OLDY,TEMP SAY CHR(23)
          STORE TEMP+1 TO TEMP
        ENDDO
* Vert line from last point
        STORE OLDY TO TEMP
        DO WHILE TEMP<YPOS+1
          @ TEMP,XPOS SAY CHR(1)
          STORE TEMP+1 TO TEMP
        ENDDO
      ENDIF
    ENDIF
  ENDIF
  STORE XPOS TO OLDX
  STORE YPOS TO OLDY
  SKIP
ENDDO
* Put in last bar's right side
IF XPOS<PLOT:RT-1
  DO WHILE DELX > 1
    STORE XPOS+1 TO XPOS
    STORE DELX-1 TO DELX
    @ YPOS,XPOS SAY CHR(23)
  ENDDO
ENDIF
DO WHILE YPOS<PLOT:BT
  @ YPOS,XPOS SAY CHR(1)
  STORE YPOS+1 TO YPOS
ENDDO
* Turn graphics off
@ 1,110 SAY ' '
? CHR(27)+CHR(71)
RETURN
