%%HP:T(3)A(D)F(.);
@ LEASTSQ by Anthony K. Donno
DIR
  LEAST
    \<< DELEQ CL\GS \GS+ CLLCD 1 'XC' STO 2 'YC' STO 3 'ORDR' STO XYR
      { { "XCOL" {
      \<< 'XC' STO DELEQ XYR
      \>>
      \<< 'XC' STO DELEQ XYR
      \>>
      \<< XC XYR
      \>> } } { "YCOL" {
      \<< 'YC' STO DELEQ XYR
      \>>
      \<< 'YC' STO DELEQ XYR
      \>>
      \<< YC XYR
      \>> } } { "ORDER" {
      \<< 'ORDR' STO DELEQ XYR
      \>>
      \<< 'ORDR' STO DELEQ XYR
      \>>
      \<< ORDR XYR
      \>> } } { "PLOT"
      \<<
        IF 'EQ' VTYPE -1 ==
        THEN SETRNG FIT
        END
        IF 'EQ' VTYPE 2 ==
        THEN EQ 1 DISP 2 WAIT
        ELSE FUNCTION PLOT GRAPH
        END XYR
      \>> } { "FIT"
      \<<
        IF 'EQ' VTYPE -1 ==
        THEN FIT
        END
        IF 'EQ' VTYPE 2 ==
        THEN EQ 1 DISP 2 WAIT
        ELSE 'EQ' RCL
        END XYR
      \>> } { "EXIT"
      \<< 0 MENU
      \>> } } TMENU
    \>>
  PLOT
    \<< ERASE \GSDAT SIZE OBJ\-> DROP DROP \-> d
      \<< 1 d
        FOR i \GSDAT i XC 2 \->LIST GET \GSDAT i YC 2 \->LIST GET R\->C C\->PX
          PIXON
        NEXT DRAX DRAW
      \>>
    \>>
  FIT
    \<< \GSDAT SIZE OBJ\-> DROP DROP \-> d
      \<<
        IF d ORDR >
        THEN d ORDR 1 + 2 \->LIST 1 CON 2 ORDR 1 +
          FOR i 1 d
            FOR j j i 2 \->LIST \GSDAT j XC 2 \->LIST GET i 1 - ^ PUT
            NEXT
          NEXT 1 d
          FOR i \GSDAT i YC 2 \->LIST GET
          NEXT d 1 2 \->LIST \->ARRY SWAP DUP DUP TRN SWAP * INV SWAP TRN *
          SWAP * OBJ\-> DROP ORDR POLY
        ELSE "ERROR: Order > Points\010______________________"
        END 'EQ' STO
      \>>
    \>>
  POLY
    \<< \-> d
      \<< -3 CF 'X' d ^ * d 1 - 0
        FOR d SWAP 'X' d ^ * + -1
        STEP
      \>>
    \>>
  SETRNG
    \<< MAX\GS XC GET MAX\GS YC GET \-> xmax ymax
      \<< MIN\GS XC GET MIN\GS YC GET \-> xmin ymin
        \<< xmax xmin XRNG ymax ymin YRNG
        \>>
      \>>
    \>>
  XYR
    \<< RCLF \-> flags
      \<< -45 CF -46 CF -47 CF -48 CF -49 CF -50 CF "Xcol:" XC \->STR +
        " Ycol:" + YC \->STR + " Order:" + ORDR \->STR +
        "\010______________________" + 1 DISP 1 FREEZE flags STOF
      \>>
    \>>
  DELEQ
    \<<
      IF 'EQ' VTYPE -1 \=/
      THEN 'EQ' PURGE
      END
    \>>
  CST { LEAST PLOT FIT { } { "PURGE"
    \<< { EQ PPAR ORDR YC XC \GSDAT } PURGE
    \>> } { "EXIT"
    \<< HOME
    \>> } }
END
