%GCL
// Callback Routine for PLOT
subroutine plotcb (id, iray)

extern id_file, id_lis,  id_lis2
extern id_but1, id_but2, id_but3, id_but4, id_but5
extern id_xcol, id_ycol, id_block
extern id_xmin, id_xmax, id_xor, id_xstp
extern id_ymin, id_ymax, id_yor, id_ystp
extern id_tit1, id_tit2, id_tit3, id_tit4
extern id_xtit, id_ytit

cdata   = gwgfil (id_file)                // Data File

idev    = gwglis (id_lis)                 // Device
cdev    = itmstr ("XWIN|CONS|POST", idev)

ipol    = gwglis (id_lis2)
%polcrv = itmstr ("LINEAR|STEP|BARS|SPLINE|PSPLINE", ipol)

%xauto = gwgbut (id_but1)                   // Scaling (Auto, User)
%xauto = 1 - %xauto

%yauto = gwgbut (id_but2)                   // Scaling (Auto, User)
%yauto = 1 - %yauto

%xscl = "LIN"
ixscl = gwgbut (id_but3)                   // X-axis scaling
if (ixscl == 1) %xscl = "LOG"

%yscl = "LIN"
iyscl = gwgbut (id_but4)                   // Y-axis scaling
if (iyscl == 1) %yscl = "LOG"

cxcol   = gwgtxt (id_xcol)                 // Data Block Columns
cycol   = gwgtxt (id_ycol)
nxcol   = atonum (cxcol)
nycol   = atonum (cycol)

cblock  = gwgtxt (id_block)
nblock  = atonum (cblock)

cxmin   = gwgtxt (id_xmin)                 // Axis system scaling
cxmax   = gwgtxt (id_xmax)
cxor    = gwgtxt (id_xor)
cxstp   = gwgtxt (id_xstp)
%xmin   = atonum (cxmin)
%xmax   = atonum (cxmax)
%xor    = atonum (cxor)
%xstep  = atonum (cxstp)
if (%xstep == 0.) free %xor, %xstep

cymin   = gwgtxt (id_ymin)
cymax   = gwgtxt (id_ymax)
cyor    = gwgtxt (id_yor)
cystp   = gwgtxt (id_ystp)

%ymin   = atonum (cymin)
%ymax   = atonum (cymax)
%yor    = atonum (cyor)
%ystep  = atonum (cystp)
if (%ystep == 0.) free %yor, %ystep

%t1     = gwgtxt (id_tit1)                 // Title
%t2     = gwgtxt (id_tit2)
%t3     = gwgtxt (id_tit3)
%t4     = gwgtxt (id_tit4)

%x      = gwgtxt (id_xtit)                 // Axis titles
%y      = gwgtxt (id_ytit)

irev    = gwgbut (id_but5)

if (datfil (cdata)   == -1) return
if (datblk (nblock)  == -1) return

xray = datray (nxcol)
yray = datray (nycol)

metafl (cdev)
if (irev == 1) scrmod ("revers")
if (irev == 0) scrmod ("erase")            // Reset Reverse

plot xray, yray
if (idev == 1 || idev == 2) unit(0)
winmod ("none")
disfin ()
end
