Viewing contents of file '../idllib/contrib/lamp/suprplot.pro'
;
;				******************
;				*** Super_Plot ***
;				******************
; 			a graphical tool to compare scans
;
; 			Written by JOUFFREY Romuald
; 			August,September,October, November, ..., etc 1995
; 			(Hoping this Help...)
;
; V01.20 09/09/96

; Procedures of this file are :
;
; *************************** Procedures
; p_rom_super_event           Event Manager for Super_Plot
; p_rom_super_plot		Plots making procedure
; p_rom_super_select		plot Getting procedure
; p_rom_super_filter		filter/copy local workspaces for plotting
; p_rom_super_done		Done button was pushed
; p_rom_cleanup, id		called when window is killed to restore colors
; p_rom_redefine_slider		
; p_rom_send_txt_wd
; ***************************** Widgets Creating Procedure
; superplot, widx	Create Super_plot Interface
;
; Little explanation on variables
; - Each Super_Plot Variable begins with s_ 
; - Local variables are normaly named 
; - sw_ stands for Super_Plot Widgets identifier variables
; - sc_ stands for Super_Plot Commons
; 
; The event procedure for superplot is called by the event_lamp_parser
; which gives it back the Uvalue as a parameter, so superplot interface
; is a real part of the whole Lamp package.


; *****************************************************************************
pro p_rom_super_event, event, test ;*******************************************
; *****************************************************************************
;
; Called when an event is generated by Super_Plot widgets tree
;

@lamp.cbk				; call back the lamp common block
common sc_superdid ,s_sym,s_err, $	; Array of boolean Set for psym , error
		s_lv,s_lx,s_lbx,s_lby	; For live annotation
common sc_superplot,s_wid,$		; # of the workspace processed (string)
		s_siz,    $		; The size of current workspace processed
		s_wset,   $		; # of the draw window
		s_hid,    $		; Array of boolean Set if hided
		s_scl,    $		; Array of boolean Set if scaled
		s_hid2,   $		; as s_hid but when s_cutall is set
		s_off_arr,$		; Array of idx 
		s_num_wrk,$		; Array of workspace number 
		s_cut,    $		; Array of boolean Set if cutting x
		s_cut_values, $		; Array of cutting values
		s_xcut,	  $		; Boolean set if cutting X
		s_filter, $		; Boolean set if filter is on
		s_color,  $		; Boolean set if colored mode
		s_show_err, $		; boolean set if show error is on
		s_normalize, $		; Boolean set if normalization is on
		s_cutall, $		; Boolean set if cutting apply to all
		s_psymb,  $		; Boolean set if plot symbol is on
		s_xmin,   $		; xmin range value (%)
		s_xmax,   $		; xmax range value (%)
		s_ctred,  $		; buffer for user color palet (red)
		s_ctgreen,$		; " (green)
		s_ctblue, $		; " (blue)
		s_scratio,$		; float (maximum scale ratio)
		s_printno,$		; int (number of next print)
		s_var1,   $
		s_var2,   $
		s_var3,   $
		s_var4,   $
		s_yscale, $		; Y scale percentage
		s_yoffset,$		; Y Offset percentage
		s_0,s_1,s_2,s_3,s_4,s_5,s_6, $	      ; local workspaces (data)
		s_e0,s_e1,s_e2,s_e3,s_e4,s_e5,s_e6, $ ; local errors
		s_x0,s_x1,s_x2,s_x3,s_x4,s_x5,s_x6, $ ; X vectors for data arrays
		s_p0,s_p1,s_p2,s_p3,s_p4,s_p5,s_p6, $ ; plotted local workspaces
		sw_id,    $		; widget id of multi_plot widget tree
		sw_drw,   $		; array of id widget draw  (0->5)
		sw_hid,   $		; array of id widget button(0->5)
		sw_lab,   $		; array of id widget label (0->5)
		sw_err			; Widget of the 'Error message' label

;WIDGET_CONTROL, event.id, Get_UValue = test
siz_test = size(test)
t1 = test(0)				; always -88 (Lamp event)
IF siz_test(1) gt 1 then t2 = test(1)	; code of the event
IF siz_test(1) gt 2 then t3 = test(2)	; another code for the event
IF siz_test(1) gt 3 then t4 = test(3)	; id of cut slider
IF siz_test(1) gt 4 then t5 = test(4)	; id of cut label
IF siz_test(1) gt 5 then t6 = test(5)	; id of X Button
IF siz_test(1) gt 6 then t7 = test(6)	; id of Y Button
IF siz_test(1) gt 7 then t8 = test(7)	; id of cutting base
IF siz_test(1) gt 8 then t9 = test(8)	; id of Workspace slider

CASE t2 OF
    353:BEGIN ; *************************** Worspace Modification
	CASE t3 OF
	    0 : BEGIN ; ------------------------------------ Worspace slider moved
		    p_rom_super_select,test,2	; Process new selection
		END
	    1 : BEGIN ; ------------------------------------ Cut slider moved
		    p_rom_super_select,test,1	; Process new selection
		END
	    2 : BEGIN ; ------------------------------------ X Button Pushed
		    s_xcut = 1			; Set flag xcut on
		    p_rom_super_select,test,1	; Process new selection
		END
	    3 : BEGIN ; ------------------------------------ Y Button Pushed
		    s_xcut = 0			; Set flag xcut off
		    p_rom_super_select,test,1	; Process new selection
		END
	    ENDCASE
	END
    354:BEGIN ; *************************** Plotting parameters modification
	CASE t3 OF
	    0 : BEGIN ; ------------------------------------ XMin slider moved
		    old_s_xmin = s_xmin
		    s_xmin = event.value
		    s_var1 = 1 & s_var2 = 0
		    IF old_s_xmin ne s_xmin THEN BEGIN
			p_rom_super_plot,0 ; Redraw
		    ENDIF
		END
	    1 : BEGIN ; ------------------------------------ XMax slider moved
		    old_s_xmax = s_xmax
		    s_xmax = event.value
		    s_var2 = 1 & s_var1 = 0
		    IF old_s_xmax ne s_xmax THEN BEGIN
			p_rom_super_plot,0 ; Redraw
		    ENDIF
		END
	    2 : BEGIN ; --------------------------------- Y_scale slider moved
		    old_s_yscale = s_yscale
		    if s_yscale lt 0 THEN s_yscale = -(event.value) ELSE $
		    			  s_yscale = (event.value) 
		    IF old_s_yscale ne s_yscale THEN BEGIN
			p_rom_super_plot,0 ; Redraw
		    ENDIF
		END
	    3 : BEGIN ; --------------------------------- Y Offset slider moved
		    old_s_yoffset = s_yoffset
		    s_yoffset = event.value
		    IF old_s_yoffset ne s_yoffset THEN BEGIN
			p_rom_super_plot,0 ; Redraw
		    ENDIF
		END
	    4 : BEGIN ; --------------------------------- Button one event
		    s_cutall = 3
		    FOR i=1,6 do BEGIN
			IF s_num_wrk(i) gt 0 then BEGIN   ; if a W is defined
			    wid = strtrim(string(s_num_wrk(i)),2)
			    V = s_cut_values(i)
			    res = execute('siz = Size(w' +wid+')')
			    IF siz(0) eq 2 THEN BEGIN ; IF WKS is bi-dimensional
				if s_cut(i) THEN BEGIN
				    res = execute('didsx=size(x'+wid+')')
				    if didsx(0) ne 1 then st=V+1 else $
				      res=execute('st = x'+wid+'(V)')
				    ii = strmid(strtrim(string(st),2),0,5)
			 	    ss='W'+wid+' '+w_numor(FIX(wid))+' X='+ii
				ENDIF ELSE BEGIN
				    res = execute('didsy=size(y'+wid+')')
				    if didsy(0) ne 1 then st=V+1 else $
				      res=execute('st = y'+wid+'(V)')
			 	    ii = strmid(strtrim(string(st),2),0,5)
				    ss='W'+wid+' '+w_numor(FIX(wid))+' Y='+ii
				ENDELSE
		            WIDGET_CONTROL, bad_id=j,sw_lab(i-1),Set_Value=ss
			    ENDIF ELSE ss='W'+wid+' '+w_numor(FIX(wid))
			ENDIF
		    ENDFOR
		    p_rom_super_select,test,1	; Process new selection
		END
	    5 : BEGIN ; --------------------------------- Button all event
		    s_cutall = 1
		    p_rom_super_select,test,1	; Process new selection
		END
	    6 : BEGIN ; --------------------------------- Button scale 0
		   s_yscale = -s_yscale
		   p_rom_super_plot,0	; Redraw
		END
	    ENDCASE
	END
    355:BEGIN ; *************************** Local W parameters modification
	CASE t3 OF
	; Here t4 is the number of processed local workspace
	    0 : BEGIN ; ------------------------- Keep Button Pushed
		    s_hid(0) = 1		        ; m_0 is now undrawable
		    s_hid(t4)= 0			; m_# t4 becomes drawable
		    s_sym(t4)=s_psymb			; psym  flag
		    s_err(t4)=s_show_err		; error flag
		    WIDGET_CONTROL, bad_id = i, sw_hid(t4-1), Set_Button=0
        	    s = strtrim(string(t4),2)	; t4 = # of local dataset
		    res = execute('s_' +s+ '=s_0')	; copy s_0 in s_i
		    res = execute('s_e'+s+ '=s_e0')	; copy s_e0 in s_ei
		    res = execute('s_x'+s+ '=s_x0')	; copy s_x0 in s_xi
		    i=0. & ii='' & V = 0
		    sw_scut=t5
		    WIDGET_CONTROL, bad_id=i,sw_scut,Get_Value = V & V=V-1
		    res = execute('siz = Size(w' +s_wid+')')
		    IF siz(0) eq 2 THEN BEGIN ; IF WKS is bi-dimensional
			IF s_xcut then BEGIN
			    res = execute('didsx=size(x'+s_wid+')')
			    if didsx(0) ne 1 then i=V+1 else $
			      res=execute('i = x'+s_wid+'(V)')
			    ii = strmid(strtrim(string(i),2),0,5)
			    s='W'+s_wid+' '+w_numor(FIX(s_wid))+'X='+ii
			ENDIF ELSE BEGIN
			    res = execute('didsy=size(y'+s_wid+')')
			    if didsy(0) ne 1 then i=V+1 else $
			      res=execute('i = y'+s_wid+'(V)')
			    ii = strmid(strtrim(string(i),2),0,5)
			    s='W'+s_wid+' '+w_numor(FIX(s_wid))+' Y='+ii
			ENDELSE 
		    ENDIF ELSE s='W'+s_wid+' '+w_numor(FIX(s_wid))
		    s_cut_values(t4)=V		; store idx of cut for 'cut one' mode 
		    s_cut(t4)=s_xcut		; store cutting axis
		    s_off_arr(t4)=V		; store idx of cut for plot idx
		    s_off_arr(0)=-1		; s_0 offset inactivated
		    s_num_wrk(t4)=FIX(s_wid)	; store number of kept workspace
		    s_num_wrk(0)=-1		; s_0 offset inactivated
		    WIDGET_CONTROL, bad_id=i, sw_lab(t4-1), Set_Value = s
		    p_rom_super_filter		; process filtering
		    p_rom_super_plot,0		; Redraw
		END
      	    1 : BEGIN ; ------------------------- Hide Button event
		    s_hid(t4) = event.select	; t4 = # of local dataset
		    i = strtrim(string(t4),2)
		    res = execute('s_s = SIZE(s_'+i+')')
		    IF s_s(0) ne 0 THEN BEGIN
			p_rom_super_plot,0	; Redraw	
		    ENDIF
        	END
    	    2 : BEGIN ; ------------------------- Scale Button event
		    s_scl(t4) = event.select	; t4 = # of local dataset
		    p_rom_super_plot,0		; Redraw
		END
    	    3 : BEGIN ; ------------------------- Clean Out Button pushed
		    s_hid=[1,1,1,1,1,1,1]	; each plot is undrawable
		    s_0 = 0			; erase local workspace 0
		    s_siz = size(s_0)
		    s_1=s_0 & s_2=s_0 & s_3=s_0	; and 1 to 6 
		    s_4=s_0 & s_5=s_0 & s_6=s_0
		    s_p1=s_0 & s_p2=s_0 & s_p3=s_0 ; Erase plotted Workspaces 
		    s_p4=s_0 & s_p5=s_0 & s_p6=s_0
		    s_off_arr =[-1,-1,-1,-1,-1,-1,-1]
		    s_num_wrk =[-1,-1,-1,-1,-1,-1,-1]   ; Clear workspace number array
		    s_cut_values=[-1,-1,-1,-1,-1,-1,-1]	; Clear cutting values
		    FOR j=0,5 do BEGIN		; Reset widget values
			WIDGET_CONTROL, bad_id=i, sw_hid(j), Set_Button=0
			WIDGET_CONTROL, bad_id=i, sw_lab(j), Set_Value=' '
		    ENDFOR
		    s_yoffset = 0		; no yoffset
		    WIDGET_CONTROL, bad_id=i, t4, Set_Value = 0
		    WSET, s_wset
		    ERASE, 255			; Clear draw window	    
		END
    	    4 : BEGIN ; ------------------------- Normalize all Button event
		    s_normalize = event.select
		    p_rom_super_plot,0 		; Redraw
		END
	    5 : BEGIN ; ------------------------- Filter Button event
		    s_filter = event.select
		    p_rom_super_filter 		; process filtering or copy
		    p_rom_super_plot,0		; Redraw
		END
	    6 : BEGIN ; ------------------------- Colored Button event
		    s_color = event.select
		    IF s_color then BEGIN
			TVLCT, s_ctred, s_ctgreen, s_ctblue, /GET
			LoadCT,12
		    ENDIF ELSE BEGIN
			TVLCT, s_ctred, s_ctgreen, s_ctblue
			s_ctred=0 & s_ctgreen=0 & s_ctblue=0
		    ENDELSE
		    FOR j=0,5 do BEGIN
			WIDGET_CONTROL,bad_id=i,sw_drw(j) ,Get_Value = w
			wset, w
			IF s_color then ERASE, j*(!D.n_colors/9)+7 else BEGIN
			    erase, 255
			    PLOTS, 0,13, /Device
			    PLOTS, FIndGen(49), SIN(FIndGen(49)/7)*10+13, /Continue, Color = 0, LineStyle = j, /Device
			ENDELSE
		    ENDFOR
		    p_rom_super_plot,0		; Redraw
		END
	    7 : BEGIN ; ------------------------- Show errors Button event
		    s_show_err = event.select
		    p_rom_super_plot,0		; Redraw		    
		END
	    8 : BEGIN ; ------------------------- Plot Symbol Button event
		    s_psymb = event.select
		    p_rom_super_plot,0		; Redraw		    
		END
	    ENDCASE
	END
    356:BEGIN ; *************************** Others global events
	CASE t3 OF
	    0 : BEGIN ; ------------------------- Print Button Pushed
		    PsFile = 'super_p'	    ; construct PS filename
		    doit=0
		    FOR i=0,6 do BEGIN
		    	IF NOT(s_hid(i)) and NOT(s_hid2(i)) then BEGIN
			    IF s_num_wrk(i) gt 0 THEN BEGIN
				doit=1
			    ENDIF
			ENDIF
		    ENDFOR
		    IF doit THEN BEGIN
			PsFile=PsFile+STRTRIM(STRING(s_printno), 2)+'.PS'
		        PRINT, 'Print Generating : '+PsFile
			wplot = !D.name
			on_ioerror, iferr
		        set_plot,'PS' & sx=7. & sy=11.5
		        device, yoffset=sy-0.5,xoffset=.5,/inches,/Landscape
			device, filename=PsFile
			device, bits_per_pixel=8,/color
			p_rom_super_plot,1	; Redraw with print option
			P_DID_PS_HEADER,7.,s_num_wrk(0)>0,PsFile
			s_printno=s_printno+1
			iferr :
			DEVICE,/close
			set_plot, wplot
		    ENDIF ELSE PRINT, string(7B)+'no print generated'
		 END
	    1 : p_rom_super_done		; DONE Button pushed

	    2 : BEGIN ; ------------------------- Motion event
			WSET,s_wset
			tmXYZ=CONVERT_COORD(event.X,event.Y,/dev,/to_data)
			XV=tmXYZ(0) & YV=tmXYZ(1) ;CURSOR,XV,YV ,/nowait,/data
			tx1='X='+strtrim(string(XV),2) & ty1='Y='+strtrim(string(YV),2)
			widget_control,bad_id=i,t4,set_value=tx1
			widget_control,bad_id=i,t5,set_value=ty1
		 END
	    3 : if n_elements(s_lv) gt 1 then BEGIN ; -------- Live Tools
			LIVE_LAMP_PLOT, 1, s_lx, s_lv, xrange=s_lbx, yrange=s_lby
	  	 ENDIF
	    ENDCASE
	END
    ENDCASE
END

; *****************************************************************************
pro p_rom_super_plot, psp ;****************************************************
; *****************************************************************************
;
; The plotting procedure
; psp stands for PoScript Printing
; if psp eq 1 then p_rom_super_plot is used to print on Postcript device
;

@lamp.cbk
common sc_superdid			; Array of boolean Set for psym
common sc_superplot			; Call Back Super_Plot block

XMin = Min(s_x0) & XMax = Max(s_x0)	; Default Values for XMin, XMax
YMin = Min(s_0)  & YMax = Max(s_0)	; and YMin, Ymax

FOR i=1,6 do BEGIN			; For each local data set
    s_s=[0] & si= strtrim(string(i),2)
    res = execute('s_s = size(s_'+si+')')
    IF s_s(0) ne 0 THEN BEGIN
	tmp = 0.
	tmm = 0.
	si = strtrim(string(i),2)
	res = execute('tmp = Min(s_x' +si+',max=tmm)')
	if XMin gt tmp then XMin = tmp	; Calculate XMin ...
	if XMax lt tmm then XMax = tmm	; Calculate XMax ...
	res = execute('tmp = Min(s_'  +si+',max=tmm)')
	if YMin gt tmp then YMin = tmp	; Calculate YMin ...
	if YMax lt tmm then YMax = tmm 	; Calculate YMax
    ENDIF
ENDFOR

; ---------------------------------- if scale 0 button is set
if s_yscale lt 0 THEN BEGIN
    butscl0=1
    s_yscale=-s_yscale
ENDIF ELSE butscl0=0

; ---------------------------------- calculate correct XRange
if (s_var1 eq 0) and (s_var2 eq 0) then BEGIN
XMinP =XMin + (XMax-XMin)/500.*s_xmin
XMaxP =XMax - (XMax-XMin)/500.*(500.-s_xmax)
s_var3 = XMinP
s_var4 = XMaxP
ENDIF

if s_var1 eq 1 then BEGIN
    XMinP =XMin + (s_var4-XMin)/500.*s_xmin
    s_var3 = XMinP
    XMaxP = s_var4
ENDIF
if s_var2 eq 1 then BEGIN
    XMaxP =XMax - (XMax-s_var3)/500.*(500.-s_xmax)
    s_var4 = XMaxP
    XMinP = s_var3
ENDIF

if butscl0 eq 1 THEN YMinP = 0 else YMinP = YMin

; ---------------------------------- calculate correct YRange
; gjk touched here!!!
  if s_normalize then begin
     YMinP=Ymin/YMax
     YMaxP=1.1
  endif else begin
     YMaxP=YMax*1.1
  endelse
; gjk end of touch  
; ---------------------------------- Calculate yoffset ...
IF s_yoffset ne 0 THEN BEGIN	; .. if offset slider not equal 0
    ; ------------------------------ Adapt array of offset on s_cutall
    ; --- woffarr is a local OFFSET Array declared for the process, it permit ...
    ; --- to preserve both s_off_arr (idx of cutting) and s_num_wrk (# of W)
    IF (s_cutall eq 1) then woffarr=s_num_wrk ELSE woffarr=s_off_arr
    IF s_normalize THEN yoffset = float(s_yoffset/100.)*float(s_yscale/s_scratio) ELSE $
    yoffset = (YmaxP-YminP)*float(s_yscale/s_scratio)*float(s_yoffset/100.)
    IF s_hid(0) then s_off_arr(0)=-1
    off_arr=woffarr
    woffarr2=intarr(n_elements(where(woffarr ge 0)), 2)
    woffarr2(*, 0)=woffarr(where(woffarr ge 0))
    woffarr2(*, 1)=indgen(n_elements(where(woffarr ge 0)))
    woffarr2(*,1)=woffarr2(SORT(woffarr2(*,0)),1)
    j=0				; replace data where it is greater or equal 0
    FOR i=0, 6 DO BEGIN
	IF off_arr(i) GE 0 THEN BEGIN
	    off_arr(i)=woffarr2(j, 1)
	    j=j+1
	ENDIF
   ENDFOR    
   YMaxP = YMaxP + Max(off_arr)*yoffset; Adapt YMaxP with offset
ENDIF ELSE BEGIN			; s_yoffset = 0
    yoffset = 0.
    off_arr =[0,0,0,0,0,0,0]
ENDELSE

s_lx = s_x0
IF n_elements(s_x1) gt n_elements(s_lx) then s_lx = s_x1
if n_elements(s_x2) gt n_elements(s_lx) then s_lx = s_x2
if n_elements(s_x3) gt n_elements(s_lx) then s_lx = s_x3
if n_elements(s_x4) gt n_elements(s_lx) then s_lx = s_x4
if n_elements(s_x5) gt n_elements(s_lx) then s_lx = s_x5
if n_elements(s_x6) gt n_elements(s_lx) then s_lx = s_x6

; ---------------------------------- printing or not printing ?
subt='' & tit ='' & xtit='' & ytit=''
IF psp THEN BEGIN		   ; printing ...
    IF s_num_wrk(0) gt 0 THEN BEGIN
	st1= strtrim(string(s_num_wrk(0)),2)
	IF s_cut(0) eq 1 THEN st2='x' ELSE st2='y'
	st3= strtrim(string(s_cut_values(0)),2)
	IF s_cut(0) eq 1 THEN $
	    str0='x'+strtrim(string(s_num_wrk(0)), 2)+'('+ $
		     strtrim(string(s_cut_values(0)), 2)+')' ELSE $
	    str0='y'+strtrim(string(s_num_wrk(0)), 2)+'('+ $
		     strtrim(string(s_cut_values(0)), 2)+')'
	res=execute('str0='+str0)
	st4= strtrim(string(str0),2)	
	subt = ' W'+st1 +st2+'#'+st3+' Value '+st4+' '
	 tit = ' '
	xtit = x_tit(s_num_wrk(0))
	ytit = y_tit(s_num_wrk(0))
    ENDIF
    IF s_color THEN $
    styles=['','D_Green','Green','Cyan', 'Purple','Pink','Red'] $
    else $
    styles=['','___','...','_ _', '._._.','..._','__ __']
    FOR i=1, 6 DO BEGIN
    IF NOT(s_hid(i)) and NOT(s_hid2(i)) THEN BEGIN
	IF s_num_wrk(i) gt 0 THEN BEGIN
	    st1= strtrim(string(s_num_wrk(i)),2)
	    IF s_cut(i) eq 1 then st2='x'
	    IF s_cut(i) eq 0 then st2='y'
	    st3= strtrim(string(s_cut_values(i)),2)
	    IF xtit EQ '' THEN xtit = x_tit    (s_num_wrk(i))
	    IF ytit EQ '' THEN ytit = y_tit    (s_num_wrk(i))
	    IF  tit EQ '' THEN  tit = w_tit    (s_num_wrk(i))
	    IF subt EQ '' THEN subt = other_tit(s_num_wrk(i))+' '
	    subt =subt +styles(i)+' W'+st1 + st2 + st3+' '
	ENDIF
    ENDIF
    ENDFOR
ENDIF ELSE WSET, s_wset		   ; ... set the correct window to plot in
ccol=7    
; ---------------------------------- Do the plot without dataset with axis

s_lbx=[XMinP,XMaxP]
s_lby=[YMinP,YMaxP*(s_yscale/s_scratio)]
s_lv =0
s_lvd=0
s_lvc=0

PLOT, s_lx,XRange=s_lbx, YRange=s_lby, title = tit, SubTitle=subt, $
			XTitle=xtit, YTitle=ytit,/NoData, Background=255,color=ccol
; ---------------------------------- Plot local workspaces #1 to 6

FOR i=1,6 do begin
    s_s=[0] & si= strtrim(string(i),2)

    ; IF s_color eq 1 then si2='0' else si2=strtrim(string(i-1),2)
    si2 = strtrim(string((i-1)*(s_color ne 1)),2)
    res = execute('s_s = size(s_'+si+')')
    ; IF s_color eq 1 then c= (i-1)*25+7 else c=ccol
    c = (((i-1)*(!D.n_colors/9)+7)*FIX(s_color eq 1))>ccol
    ; ------------------------------ Calculate normalization parameter
    YNor =0.
;   res = execute('YNor = Max(s_p'+si+') - Min(s_p'+si+')')
; gjk The following line makes a start on getting the normalisation correct
    res = execute('YNor = Max(s_p'+si+')') 
    ; IF n_normalize ne 1 then YNor = 1.
    YNor = FLOAT(s_normalize ne 1)+YNor*FLOAT(s_normalize eq 1)
    ; ------------------------------ Calculate scaling parameter
    ; if local w isn't scaled, then yscale=s_scratio/s_yscale else yscale=1 
    ; this is to cancel the effect of YRange modified by s_yscale
    yscale = FLOAT(s_scl(i) eq 1)+(s_yscale/s_scratio)*FLOAT(s_scl(i) ne 1)
    IF s_s(0) ne 0 THEN $		; plot only not empty workspace
	IF not(s_hid(i)) and not(s_hid2(i)) THEN BEGIN ; and not hided workspace
	    Numerator = '/YNor-YMin)*yscale)+yoffset*off_arr(i)'
	    res = execute('s_lvd=(YMin+(s_p'+si+Numerator)
	    psymb=s_sym(i)*i & IF psymb GE 3 THEN psymb=psymb+1
	    IF psymb EQ 0 THEN psymb=!P.PSYM
	    st  = 'OPLOT, s_x'+si+',s_lvd ,color=c, PSym=psymb, linestyle = '+si2
	    res = execute(st)
	    if n_elements(s_lv) eq 1 then begin s_lv=s_lvd & s_lvc=s_lx(0)+n_elements(s_lx)
	    endif else begin s_lf=0 & res=execute('s_lf=s_x'+si+'(0)+n_elements(s_x'+si+')')
				if s_lf eq s_lvc then s_lv=[[s_lv],[s_lvd]]
	    endelse
	    ; ------------------------------ Plotting corrected data versus errors
	    IF s_err(i) THEN BEGIN
		res = execute('ee=s_e'+si)
		res = execute('wmax=MAX(s_'+si+')')
		IF N_ELEMENTS(ee) LE 1 THEN BEGIN
		    res = execute('s_e'+si+'=SQRT(s_'+si+')')
		    res = execute('ee=s_e'+si)
		ENDIF
		IF MAX(ee)*(wmax+1) eq sqrt(wmax) THEN BEGIN
		    opp1='*(1+ee)'
		    opp2='*(1-ee)'
		ENDIF ELSE BEGIN
		    opp1='+ee'
		    opp2='-ee'
		ENDELSE
		keepcol=!P.COLOR & !P.COLOR=c
		st  = 'ERRPLOT, s_x'+si+', (YMin+((s_p'+si+opp1+')'+numerator+ $
					', (YMin+((s_p'+si+opp2+')'+numerator
		res = EXECUTE(st)
		!P.COLOR=keepcol
	    ENDIF
	ENDIF
ENDFOR

; ---------------------------------- plot local workspace #0
IF s_siz(0) ne 0 THEN $
    IF NOT(s_hid(0)) and not(s_hid2(0)) THEN BEGIN
;	YNor = Max(s_p0) - Min(s_p0)
	YNor = Max(s_p0) 
	; IF n_normalize ne 1 THEN YNor = 1.
	YNor = FLOAT(s_normalize ne 1)+YNor*FLOAT(s_normalize eq 1)
	s_lvd= YMin+(s_p0/YNor-YMin)  +yoffset*off_arr(0)
	OPLOT,s_x0,s_lvd ,Thick=2-s_color,color=0, PSym=7*s_psymb

	if n_elements(s_lv) eq 1 then s_lv=s_lvd $
	else begin 	s_lf=s_x0(0) + n_elements(s_x0)
			if s_lf eq s_lvc then s_lv=[[s_lv],[s_lvd]]
	endelse
	; ------------------------------ Plotting corrected data versus errors
	IF s_show_err THEN BEGIN
	    IF N_ELEMENTS(s_e0) LE 1 THEN BEGIN
		s_e0=SQRT(s_0)
	    ENDIF
	    wmax=MAX(s_0)
	    IF MAX(s_e0)*(wmax+1) eq sqrt(wmax) THEN BEGIN
		opp1='*(1+s_e0)'
		opp2='*(1-s_e0)'
	    ENDIF ELSE BEGIN
		opp1='+s_e0'
		opp2='-s_e0'
	    ENDELSE
	    keepcol=!P.COLOR & !P.COLOR=0
	    st  = 'ERRPLOT,s_x0,YMin+(s_p0'+opp1+')/YNor-YMin+yoffset*off_arr(0)'+$
			      ',YMin+(s_p0'+opp2+')/YNor-YMin+yoffset*off_arr(0)
	    res = EXECUTE(st)
	    !P.COLOR=keepcol
	ENDIF
    ENDIF

; ---------------------------------- reset y_scale if negative
IF butscl0 eq 1 THEN s_yscale=-s_yscale

END

; *****************************************************************************
pro p_rom_super_select,test, flg ;*********************************************
; *****************************************************************************
;
; Called when a NEW Workspace is selected
; (New Workspace number, Cutting Axis or Cutting Value) 
; flag is gt 0 if a new workspace is invoked
; flag eq 2 if workspace slider was moved, to invoke new w in cuting all mode
;

@lamp.cbk			; call back the lamp common block
common sc_superplot		; Call Back Super_Plot block

sw_scut = test(3)	; id of cut slider
sw_lcut = test(4)	; id of cut label
sw_bty  = test(6)	; id of Y Button
sw_cutb = test(7)	; id of cutting base
sw_sw   = test(8)	; id of workspace slider 

IF (flg eq 2 and s_cutall eq 1) or (flg gt 0 and s_cutall ne 1) THEN BEGIN
    WIDGET_CONTROL,bad_id=i,sw_sw,Get_Value = widx ; Get selected Workspace #
    s_wid= strtrim(string(widx),2)		; get new workspace #
    res =execute('s_siz=size(w' +s_wid +')' )
    ; --------- if W isn't correct
    IF (s_siz(0) lt 1) or (s_siz(0) gt 2) then BEGIN  
	p_rom_send_txt_wd, sw_err, 'Mono or Bidimensional W only'
	print, string(7b)	; BELL to signify error
	s_hid(0) = 1		; s_0 becomes undrawable
    WIDGET_CONTROL, bad_id=i,sw_cutb, Sensitive=0  
    ENDIF ELSE BEGIN
	IF flg eq 2 then p_rom_send_txt_wd, sw_err,'W'+s_wid+' '+strmid(w_tit(FIX(s_wid)),0,20)
        IF flg eq 2 then IF (s_siz(0) eq 2) THEN WIDGET_CONTROL, bad_id=i,sw_cutb, /Sensitive
	s_hid(0) = 0		; s_0 becomes drawable
    ENDELSE
ENDIF

IF s_cutall eq 1 THEN BEGIN
    IF flg gt 0 then wait,.6
    p_rom_send_txt_wd, sw_err,'Cut is applied on ALL W'
ENDIF

; ----------------------- Retrieve Cutting Value
WIDGET_CONTROL, bad_id=i, sw_scut, Get_Value = V & V=V-1

if s_hid(0) eq 0 then s_off_arr(0)=V
s_cut_values(0)=V
s_cut(0)=s_xcut
IF (s_cutall eq 1) THEN s_num_wrk(0)=FIX(s_wid)
s_num_wrk(0)=FIX(s_wid)
slide_max = 0

; ------------------------------- For all W if cutall is on (1 or 3)
; ------------------------------- For W#0 if cutall is off
s_e0=0
FOR j=0,6*FIX(s_cutall eq 1 or s_cutall eq 3) do BEGIN
    IF s_num_wrk(j) gt 0 then BEGIN   ; if a W is defined
        IF (s_cutall eq 0) or (s_cutall eq 3) THEN V=s_cut_values(j)
	wid = strtrim(string(s_num_wrk(j)),2)
	si =  strtrim(string(j),2)
	res = execute('siz = Size(w' +wid+')')
	IF siz(0) eq 1 THEN BEGIN		; wk has one dimension
	    IF NOT(s_cutall) THEN BEGIN
		WIDGET_CONTROL, bad_id=i, sw_lcut, Set_Value=''
		WIDGET_CONTROL, bad_id=i, sw_cutb, Sensitive = 0
	    ENDIF
	    res = execute('s_' +si+' = w'+wid)	; copy workspace array
	    res = execute('s_e'+si+' = e'+wid)	; copy error array
	    s_cut(j)=-1
	    res = execute('s_x'+si+' = x'+wid)
	    ss='W'+wid+' '+w_numor(FIX(wid))
	    res = execute('nb_element =n_elements(s_x'+si+')')
	    IF nb_element ne siz(1) THEN $
	    res = execute('s_x'+si+' = indgen(siz(1))')
        ENDIF ELSE BEGIN			; wk has two dimensions
	    cutx=s_xcut
	    IF (s_cutall eq 0 or s_cutall eq 3) then cutx = s_cut(j)
	    ; ------------------ Get correct Cut in correct W
	    s = 0.
	    res = execute('didsx=size (x'+wid+')')
	    res = execute('didsy=size (y'+wid+')')
	    IF cutx THEN BEGIN
		smax=siz(1)-1  		; define new slider max
	        IF ((V ge siz(1)) AND s_cutall eq 1) then BEGIN
		    s_hid2(j)=1
		ENDIF ELSE BEGIN
		    s_hid2(j)=0
		IF V ge siz(1) then V=siz(1)-1
		if didsy(0) ne 2 then res = execute('s_x'+si+' = y'+wid) else $
				      res = execute('s_x'+si+' = reform(y'+wid+'(V,*))') 
		res = execute('nb_element =n_elements(s_x'+si+')')
		IF nb_element ne siz(2) THEN $
		res = execute('s_x'+si+' = indgen(siz(2))')

		if didsx(0) ne 1 then st=V+1 else $
		  res=execute('st = x'+wid+'(V)')
		ii = strmid(strtrim(string(st),2),0,5)
		ss='W'+wid+' '+w_numor(FIX(wid))+' X='+ii
		res = execute('s_' +si+' = REFORM(w'+wid+'(V,*))') 
		res = execute('s_e'+si+' = REFORM(e'+wid+'(V,*))') 
		s = strtrim(string(st),2)+' '+x_tit(FIX(wid))
		ENDELSE
	    ENDIF ELSE BEGIN
		smax=siz(2)-1 		; define new slider max
	        IF ((V ge siz(2)) AND s_cutall eq 1) then BEGIN
		    s_hid2(j)=1
		ENDIF ELSE BEGIN
		    s_hid2(j)=0
		IF V ge siz(2) then V=siz(2)-1
		if didsx(0) ne 2 then res = execute('s_x'+si+' = x'+wid) else $
				      res = execute('s_x'+si+' = reform(x'+wid+'(*,V))') 
		res = execute('nb_element =n_elements(s_x'+si+')')
		IF nb_element ne siz(1) THEN $
		res = execute('s_x'+si+' = indgen(siz(1))')

		if didsy(0) ne 1 then st=V+1 else $
		  res=execute('st = y'+wid+'(V)')
		ii = strmid(strtrim(string(st),2),0,5)
		ss='W'+wid+' '+w_numor(FIX(wid))+' Y='+ii
		res = execute('s_'+si+' = w'+wid+'(*,V)')
		res = execute('s_e'+si+' = e'+wid+'(*,V)')
		s = strtrim(string(st),2)+' '+y_tit(FIX(wid))
		ENDELSE
	    ENDELSE
            IF (s_cutall eq 0 or s_cutall eq 3) THEN BEGIN
	        WIDGET_CONTROL, bad_id=i, sw_lcut, Set_Value = s
		p_rom_redefine_slider, sw_scut, V+1, smax+1		
	    ENDIF ELSE BEGIN
	    IF slide_max lt smax then slide_max = smax
	    IF j ne 0 THEN WIDGET_CONTROL,bad_id=i,sw_lab(j-1),Set_Value=ss
	    ENDELSE
	ENDELSE
    ENDIF
ENDFOR
IF (s_cutall eq 1) THEN BEGIN
    WIDGET_CONTROL, bad_id=i, sw_lcut, Set_Value = 'idx='+strtrim(string(V),2)
    WIDGET_CONTROL, bad_id=i, sw_cutb, /Sensitive
    WIDGET_CONTROL, bad_id=i, sw_scut, Set_Slider_Max = slide_max+1
ENDIF
p_rom_super_filter	; process filtering
p_rom_super_plot,0	; Redraw		    
if s_cutall eq 3 then s_cutall=0	; end of the redraw calculation
END

; *****************************************************************************
PRO p_rom_super_filter ;*******************************************************
; *****************************************************************************
;
; If filtering is on,  copy filtered s_# into s_p#
; If filtering is off, copy s_# in s_p#
;

common sc_superplot

FOR i=0,6 do BEGIN
    s_s=[0] & si= strtrim(string(i),2)
    IF s_filter then BEGIN
	res = execute('s_s = size(s_'+si+')')
	IF s_s(0) ne 0 THEN BEGIN
	    res = execute('s_p'+si+' = SMOOTH(MEDIAN(s_'+si+',3),3)') 
	ENDIF
    ENDIF ELSE $
	    res = execute('s_p'+si+' = s_'+si) 	
ENDFOR
END

; *****************************************************************************
PRO p_rom_super_done ;*********************************************************
; *****************************************************************************
;
; Called when Done Button is pushed
;
@lamp.cbk
COMMON sc_superplot

IF s_color THEN $	; if color table has been saved
	TVLCT, s_ctred,s_ctgreen,s_ctblue ; restore old color table
if lamp_b1 gt 0 then WIDGET_CONTROL,bad_id=i,sw_id,map=0 ; Hide Super_Plot Window
if lamp_b1 le 0 then WIDGET_CONTROL,bad_id=i,sw_id,/destroy
return
END

; *****************************************************************************
PRO p_rom_cleanup, id
; *****************************************************************************
;
; Called when Superplot window is dying
;
common sc_superplot

IF s_color then TVLCT, s_ctred, s_ctgreen, s_ctblue
END

; *****************************************************************************
PRO p_rom_redefine_slider, wid, value, maxi ;**********************************
; *****************************************************************************
;
; Redefine slider MAXImum and slide VALUE for the WID slider
;
WIDGET_CONTROL, bad_id=i, wid, Set_Slider_Max = maxi
WIDGET_CONTROL, bad_id=i, wid, Set_Value = value
END

; *****************************************************************************
PRO p_rom_send_txt_wd, wid, str ;**********************************************
; *****************************************************************************
;
; Modifie STR value for the WID slider
;

WIDGET_CONTROL, bad_id=i, wid, Set_Value = str
END

; ****************************************************************************
pro suprplot, widx ;************************************************
; ****************************************************************************
;
; Create the Super_Plot interface.
; widx is an optional default workspace number (between 1 and 20)
;

@lamp.cbk				; call back the lamp common block
common sc_superdid			; Array of boolean Set for psym
common sc_superplot			; Call Back Super_Plot block

if (!D.flags and 65536)      eq 0 then print,'set_plot,"X" before using' else $
if xregistered('SUPER_PLOT') le 0 then BEGIN	; If Super_Plot doesn't exist..
    P_MUS,'mus_harp'				; PLAY a tune
    ;*********************************************Create Widget tree

    ; -------------------------------------------- Variables initialisation
    s_xcut      = 0				; Cutting Y axis is default
    s_filter    = 0				; Filter Off is default
    s_color     = 0				; Black/White mode
    s_show_err  = 0				; Show errors is off
    s_normalize = 0				; Normalization Off
    s_cutall    = 0				; cutting doesn't apply to all
    s_psymb     = 0				; plot symbol (*) or not
    s_xmin      = 0				; No X scale
    s_xmax      = 500				; No X scale
    s_ctred	= 0				; red
    s_ctgreen	= 0				; green
    s_ctblue	= 0				; blue
    s_scratio	= 500.				; scale ratio range
    s_yscale    = s_scratio			; no scale is default
    s_printno    = 1				; next print number is 1
    s_lv	= 0				; plot array for live_plot
    s_var1	= 0
    s_var2	= 0
    s_var3	= 0
    s_var4	= 0
    s_yoffset   = 0				; no offset is default
    s_hid       =[1,1,1,1,1,1,1]		; Set all hided flags on
    s_scl       =[1,1,1,1,1,1,1]		; Set all scaled flags on
    s_sym       =[0,0,0,0,0,0,0]		; Set all psym to 0
    s_err       =[0,0,0,0,0,0,0]		; Set all show_error to 0
    s_hid2      =[0,0,0,0,0,0,0]		; No plot hided (cutall)
    s_off_arr   =[-1,-1,-1,-1,-1,-1,-1]		; Offsetarray Inactive
    s_num_wrk   =[-1,-1,-1,-1,-1,-1,-1]		; Clear workspace number array
    s_cut       =[0,0,0,0,0,0,0]		; cutting axis Y is default
    s_cut_values=[-1,-1,-1,-1,-1,-1,-1]		; Clear cutting values
    s_1=0    & s_2=s_1  & s_3=s_1		; Clear local Workspaces 
    s_4=s_1  & s_5=s_1  & s_6=s_1
    s_p1=0   & s_p2=s_1 & s_p3=s_1		; Clear plotted Workspaces 
    s_p4=s_1 & s_p5=s_1 & s_p6=s_1

    np=6					; np=number of plots
    sw_lab=lonarr(np) & sw_hid=lonarr(np) & sw_scl=lonarr(np) & sw_drw=lonarr(np)

    IF N_ELEMENTS(widx) eq 0 then widx=0
    IF widx le 0 then s_wid='1' $
	ELSE s_wid= strtrim(string(widx),2)	; sw_wid=current workspace number
    res=execute('s_siz=size(w'+s_wid+')')
    if s_siz(0) eq 1 or s_siz(0) eq 2 then s_hid(0)=0

    ; Get correct slider cut max
    s=[0] & res = execute('s = size(y'+s_wid+')')
    if s(0) eq 2 then nb = s(2)-1 else nb = s(1)-1
    IF nb eq 0 then nb=1

    ; the whole lamp size depending modifications is here
    xsiz	=800				; Width of SuperPlot Draw
    if lamp_siz gt 900 then ysiz=480 else ysiz=380
    if lamp_siz lt 800 then BEGIN	; adapt help text to lamp size
	txt1 = 'Select Workspace you want to see, its cutting axis and cutting value.'
        txt2 = 'Fix it by pushing one of the "Keep as" buttons. Press "HELP" for more'	
	xsiz=480 & ysiz=250		; adapt plotting window size
	txt3='Keep'			; adapt text button
	txt4='Hide' & txt5='Scale'
	txt6='Hi'   & txt7='Sc' & txt8='___________'
	sl_size=15
	sl_siz=xsiz
    ENDIF ELSE BEGIN
	txt1  = 'Select Workspace you want to see, its cutting axis and cutting value.'+ $
        	'Fix it by pushing one of the "Keep as" buttons. Press "HELP" for more'
	txt2  = ''
	txt3='Keep as'
	txt4='Hide' & txt5='Scale'
	txt6='Hide' & txt7='Scale' & txt8='________________'
	sl_size=16
	sl_siz=xsiz-100
    ENDELSE

    ; --------------------------------- Create SUPER_PLOT Interface

    sw_id	=WIDGET_BASE  (title='Lamp Super Plot Version Sep 1998',/column, $
				Resource_Name='lampdon')
    sw_l	=WIDGET_LABEL (sw_id,Value=txt1 ,Font=ft_smaller)
    if txt2 ne '' then sw_l=WIDGET_LABEL (sw_id,Value=txt2 ,Font=ft_smaller)
    sw_b00      =WIDGET_BASE  (sw_id  ,/Row)
    sw_b0	=WIDGET_BASE  (sw_b00 ,/Column, /Frame)
    sw_b1	=WIDGET_BASE  (sw_b0  ,/Row)
    sw_sw	=WIDGET_SLIDER(sw_b1,Title='',Minimum=1,Maximum=20,Value=s_wid,$
    				Font=ft_b_normal, Xsize=sl_siz-300, YSize=sl_size)
    sw_err	=WIDGET_LABEL (sw_b1,Value='... Select your WorkSpace # ...',YSize=sl_size+15, $
				Resource_Name='discret', Font=ft_b_normal)
    sw_b2	=WIDGET_BASE  (sw_b0  ,/Row)
    sw_scut	=WIDGET_SLIDER(sw_b2,Title='',Minimum=0+1,Maximum=nb+1,/Drag,$
				Font=ft_b_normal,Xsize=sl_siz-300, YSize=sl_size)
    sw_bxy	=WIDGET_BASE  (sw_b2,/Row,/Exclusive)
    sw_btx	=WIDGET_BUTTON(sw_bxy ,Value='X',Font=ft_b_bigger,/No_Release)
    sw_bty	=WIDGET_BUTTON(sw_bxy ,Value='Y',Font=ft_b_bigger,/No_Release)
    sw_lcut	=WIDGET_LABEL (sw_b2,Value='Cut at:'         ,Font=ft_b_bigger)
    sw_lcutv	=WIDGET_LABEL (sw_b2,Value='----------------',Font=ft_b_normal, $
				Resource_Name='discret')
    sw_b        =WIDGET_BASE  (sw_b00, /Frame, /Column)
    sw_lbt      =WIDGET_LABEL (sw_b,Value='Apply cut to',Font=ft_normal)
    sw_bb       =WIDGET_BASE  (sw_b,/Exclusive,/Column)
    sw_btone    =WIDGET_BUTTON(sw_bb,Value='current W',Font=ft_smaller)
    sw_btall    =WIDGET_BUTTON(sw_bb,Value='ALL Wk.Sp.',Font=ft_smaller)

    sw_motio	=WIDGET_BASE  (sw_b00,/column)
    bid		=WIDGET_LABEL (sw_motio,Value='X & Y Cursor'   ,Font=ft_b_normal)
    sw_motx	=WIDGET_LABEL (sw_motio,Value='X= ----------------',Font=ft_normal)
    sw_moty	=WIDGET_LABEL (sw_motio,Value='Y= ----------------',Font=ft_normal)

    sw_b3	=WIDGET_BASE  (sw_id  ,/Column,Frame=2)
    sw_b31	=WIDGET_BASE  (sw_b3  ,/Row)

    FOR i=1,np do BEGIN
	sw_b311 	=WIDGET_BASE  (sw_b31, /Column, /Frame)
	sw_b312 	=WIDGET_BASE  (sw_b311,/Row)
	sw_bts		=WIDGET_BUTTON(sw_b312,Value=txt3 ,Font=ft_b_normal, $
				UValue=[-88,355,0,i,sw_scut])
 	sw_drw(i-1)	=WIDGET_DRAW  (sw_b312, XSize=xsiz/18+5, YSize=26)
	sw_b3111=WIDGET_BASE  (sw_b311,/Row, /NonExclusive)
	IF i eq 1 then BEGIN
	sw_hid(0)	=WIDGET_BUTTON(sw_b3111,Value=txt4 ,Font=ft_normal, $
				UValue=[-88,355,1,i], Resource_Name='discret')
	sw_scl(0)	=WIDGET_BUTTON(sw_b3111,Value=txt5 ,Font=ft_normal  , $
				UValue=[-88,355,2,i], Resource_Name='discret')
	ENDIF ELSE BEGIN
	sw_hid(i-1)	=WIDGET_BUTTON(sw_b3111,Value=txt6 ,Font=ft_normal, $
				UValue=[-88,355,1,i], Resource_Name='discret')
	sw_scl(i-1)	=WIDGET_BUTTON(sw_b3111,Value=txt7 ,Font=ft_normal  , $
				UValue=[-88,355,2,i], Resource_Name='discret')
	ENDELSE
	sw_lab(i-1)	=WIDGET_LABEL (sw_b311,Value=txt8, Font=ft_smaller)
    ENDFOR

    sw_b32	=WIDGET_BASE  (sw_b3    ,/Row)
    sw_b321	=WIDGET_BASE  (sw_b32   ,/Column)
    sw_ssc	=WIDGET_SLIDER(sw_b321  ,Title='' ,Minimum=1,Maximum=s_scratio,$
    				Value=s_scratio,/Suppress_Value,/Vertical,/Drag,$
				YSize=ysiz,XSize=sl_size)

    sw_draw	=WIDGET_DRAW  (sw_b32   ,Retain=2,Xsize=xsiz,Ysize=ysiz,/motion_events)
    sw_syoffset	=WIDGET_SLIDER(sw_b32   ,Title='' ,Minimum=0,Maximum=100,Value=0,/Drag,$
				/Suppress_Value,/Vertical,YSize=ysiz,XSize=sl_size)
    sw_b33	=WIDGET_BASE  (sw_b3    ,/Row)
    sw_basebt	=WIDGET_BASE  (sw_b33  , /NonExclusive)
    sw_btscl0	=WIDGET_BUTTON(sw_basebt, Value='', XSize=sl_size)
    sw_sxmin	=WIDGET_SLIDER(sw_b33,Title='X_min' ,Minimum=0,Maximum=499,/Drag, $
				Value=0 ,/Suppress_Value,Xsize=xsiz/2, $
				YSize=sl_size, Font=ft_b_normal) 
    sw_sxmax	=WIDGET_SLIDER(sw_b33,Title='X_max' ,Minimum=1,Maximum=500,/Drag, $
				Value=500,/Suppress_Value,Xsize=xsiz/2, $
				YSize=sl_size, Font=ft_b_normal)
    sw_b33	=WIDGET_BASE  (sw_b3   ,/row)
    sw_btco	=WIDGET_BUTTON(sw_b33  ,Value='Reset', Font=ft_b_normal, $
				UValue=[-88,355,3,sw_syoffset])
    sw_btp	=WIDGET_BUTTON(sw_b33  ,Value='Print'    , Font=ft_b_normal, $
				UValue=[-88,356,0])
    sw_bta	=WIDGET_BUTTON(sw_b33  ,Value='Annot.' , Font=ft_b_normal)
    sw_b331	=WIDGET_BASE  (sw_b33  ,/Row, /NonExclusive)
    sw_btn	=WIDGET_BUTTON(sw_b331 ,Value='Norm', $
				Font=ft_b_normal,UValue=[-88,355,4])
    sw_btf	=WIDGET_BUTTON(sw_b331 ,Value='Filtr', $
				Font=ft_b_normal,UValue=[-88,355,5])
    sw_btc	=WIDGET_BUTTON(sw_b331 ,Value='Color', $
				Font=ft_b_normal,UValue=[-88,355,6])
    sw_pltsymb	=WIDGET_BUTTON(sw_b331 ,Value='Symb', $
				Font=ft_b_normal,UValue=[-88,355,8])
    sw_bterr	=WIDGET_BUTTON(sw_b331 ,Value='Err', $
				Font=ft_b_normal,UValue=[-88,355,7])
    sw_bthelp	=WIDGET_BUTTON(sw_b33  ,Value='Help' ,$
 				Font=ft_b_normal,UValue=[-88,591,0])
    sw_btdone	=WIDGET_BUTTON(sw_b33  ,Value='Done' , $
				Font=ft_b_normal,UValue=[-88,356,1])
		 put_logo,sw_b33

    ; ************Set UValues to permit widget id knowledge in parsed procedures 
    WIDGET_CONTROL,bad_id=i,sw_sw ,Set_UValue= $
			[-88,353,0,sw_scut,sw_lcutv,sw_btx,sw_bty,sw_b2,sw_sw]
    WIDGET_CONTROL,bad_id=i,sw_scut ,Set_UValue= $
			[-88,353,1,sw_scut,sw_lcutv,sw_btx,sw_bty,sw_b2,sw_sw]
    WIDGET_CONTROL,bad_id=i,sw_btx ,Set_UValue= $
			[-88,353,2,sw_scut,sw_lcutv,sw_btx,sw_bty,sw_b2,sw_sw]
    WIDGET_CONTROL,bad_id=i,sw_bty ,Set_UValue= $
			[-88,353,3,sw_scut,sw_lcutv,sw_btx,sw_bty,sw_b2,sw_sw]
    WIDGET_CONTROL,bad_id=i,sw_btone ,Set_UValue= $
			[-88,354,4,sw_scut,sw_lcutv,sw_btx,sw_bty,sw_b2,sw_sw]
    WIDGET_CONTROL,bad_id=i,sw_btall ,Set_UValue= $
			[-88,354,5,sw_scut,sw_lcutv,sw_btx,sw_bty,sw_b2,sw_sw]

    ; --------------------------------- Set correct UValues
    WIDGET_CONTROL, bad_id=i, sw_sxmin   , Set_UValue=[-88,354,0,sw_sxmax]
    WIDGET_CONTROL, bad_id=i, sw_sxmax   , Set_UValue=[-88,354,1,sw_sxmin]
    WIDGET_CONTROL, bad_id=i, sw_ssc     , Set_UValue=[-88,354,2]
    WIDGET_CONTROL, bad_id=i, sw_syoffset, Set_UValue=[-88,354,3]
    WIDGET_CONTROL, bad_id=i, sw_btscl0  , Set_UValue=[-88,354,6,sw_btscl0]

    ; --------------------------------- Construct Widget Tree	
    bid=sys_dep('DYNLAB', sw_id, 1)
    WIDGET_CONTROL,bad_id=i,sw_id, Group_Leader=lamp_b1, /Realize & put_logo
    ; --------------------------------- Get the Window id of draw widget
    WIDGET_CONTROL,bad_id=i,sw_draw,Get_Value =s_wset
    WIDGET_CONTROL,bad_id=i,sw_draw,Set_UValue=[-88,356,2,sw_motx,sw_moty]
    ; --------------------------------- Set correct UValue for Annotate Button
    if sys_dep('VERSION') ge 5.1 then $
    WIDGET_CONTROL,bad_id=i,sw_bta,Set_UValue=[-88,356,3] else $
    WIDGET_CONTROL,bad_id=i,sw_bta,Set_UValue=[-88,346, s_wset ]
    ; --------------------------------- set cut 'Y' button on
    WIDGET_CONTROL,bad_id=i,sw_bty ,/Set_Button
    ; --------------------------------- set btone button on
    WIDGET_CONTROL,bad_id=i,sw_btone ,/Set_Button
    ; --------------------------------- set all SCALED Buttons to on
    FOR j=0,5 do WIDGET_CONTROL,bad_id=i,sw_scl(j) ,/Set_Button
    ; --------------------------------- Draw lines into widget draws
    FOR j=0,5 do BEGIN
	WIDGET_CONTROL,bad_id=i,sw_drw(j) ,Get_Value = w
	wset, w & erase, 255
	PLOTS, 0,13, /Device
	PLOTS, FIndGen(49), SIN(FIndGen(49)/7)*10+13, /Continue, Color = 0, $
		LineStyle = j, /Device
    ENDFOR
    
    ; --------------------------------- Send all Widget tree to Lamp Parser
    IF lamp_b1 gt 0  THEN $
    XMANAGER, 'SUPER_PLOT' ,sw_id,event_handler='LAMP_EVENT_PARSER', $
    					/Just_Reg, Cleanup='p_rom_cleanup'
    ; --------------------------------- END OF INTERFACE GENESIS

    ; --------------------------------- Generate a slider W event to 
    ; --------------------------------- have a plot immediatly
    v = [-88,353,0,sw_scut,sw_lcutv,sw_btx,sw_bty,sw_b2,sw_sw]
    p_rom_super_select,v,1
    IF lamp_b1 le 0  THEN XMANAGER, 'SUPER_PLOT' ,sw_id,$
			  event_handler='LAMP_EVENT_PARSER',Cleanup='p_rom_cleanup'

ENDIF ELSE BEGIN
    ; if color mode is on, set best color table
    IF s_color THEN LOADCT, 12
    WIDGET_CONTROL,bad_id=i,sw_id,map=1	; and show existing Multi_Plot	
ENDELSE
RETURN
END