routine CHART.CTRL given DLG.FIELD, DLG.PTR yielding STATUS
''
''    AUTHOR: Steve Bailey
''    CREATED: 2-23-96
''    DESCRIPTION:
''        Control routine for the dialog box which allows the user to set
''        attributes of the chart.
''

define DLG.FIELD as a text variable
define DLG.PTR as a pointer variable
define STATUS as an integer variable

define TITLE, XAXIS.TITLE, YAXIS.TITLE, Y2AXIS.TITLE as text variables
define SUBDIALOG.PTR as a pointer variable
define COMPONENT.VALUE as a real variable
define COMPONENT.ID as a integer variable
define PROC.ID, FIELD.ID as a text variable
define DS.NUM as an integer variable

let STATUS = 0

if DLG.FIELD = "INITIALIZE" or DLG.FIELD = "BACKGROUND"
    return
always

  '' Encoded in the field name is the procedure and component id described in
  '' preamble
let PROC.ID = SUBSTR.F(DLG.FIELD, 1, 3)
write SUBSTR.F(DLG.FIELD, 4, LENGTH.F(DLG.FIELD)) as T * using the buffer
read COMPONENT.ID as I 3 using the buffer

let COMPONENT.VALUE = DDVAL.A(DFIELD.F(DLG.FIELD, DLG.PTR))
let DS.NUM = DDVAL.A(DFIELD.F("DSN  0", DLG.PTR))

'' check to see which button in the dialog was pressed. 
'' Show the appropriate sub dialog to allow other chart parameters to
'' be defined
select case PROC.ID
  case "FLD"
    call SET.CHART.FIELD.R(CHART.PTR, COMPONENT.ID, COMPONENT.VALUE)
    display CHART.PTR
    call PLOT.DATA

  case "OPT"
    call SET.CHART.OPTION.R(CHART.PTR, COMPONENT.ID, INT.F(COMPONENT.VALUE))
    display CHART.PTR

  case "DSO"
    call SET.CHART.DSOPTION.R(CHART.PTR, DS.NUM, COMPONENT.ID, 
         INT.F(COMPONENT.VALUE))
    display CHART.PTR

  case "TTL"
    let TITLE = DTVAL.A(DFIELD.F("TTL  1", DLG.PTR))
    let XAXIS.TITLE = DTVAL.A(DFIELD.F("TTL  2", DLG.PTR))
    let YAXIS.TITLE = DTVAL.A(DFIELD.F("TTL  3", DLG.PTR))
    let Y2AXIS.TITLE = DTVAL.A(DFIELD.F("TTL  4", DLG.PTR))

    call SET.GRAPH.TITLE.R(CHART.PTR, TITLE)
    call SET.CHART.TITLES.R(CHART.PTR, XAXIS.TITLE, YAXIS.TITLE, Y2AXIS.TITLE)
    display CHART.PTR

  case "DSI"
    call SET.CHART.DSINTERVAL.R(CHART.PTR, DS.NUM, COMPONENT.VALUE)
    display CHART.PTR

  case "DST"
    let TITLE = DTVAL.A(DFIELD.F("DST  0", DLG.PTR))
    call SET.CHART.DSTITLE.R(CHART.PTR, DS.NUM, TITLE)
    display CHART.PTR

  case "PRT"
    show SUBDIALOG.PTR with "part.frm"
    let DDVAL.A(SUBDIALOG.PTR) = 2 '' lower right
    let FIELD.ID = ACCEPT.F(SUBDIALOG.PTR, 'PART.CTRL')
    let FIELD.ID = FIELD.ID

  case "QUT"
    let STATUS = 1

  default
endselect

return
end
