;******************************************************************************
;* File name: ql_display_data.pro                                             *
;*                                                                            *
;* Content  : 	ql_draw_axis                                                  *
;*              ql_display_data                                               *
;*              ql_update_banner                                              *
;*                                                                            *
;*                                                                            *
;* Date		Author		Comment                                       *
;* -------------------------------------------------------------------------- *
;* 10-01-94     E.PETIT		Creation                                      *
;* 18-01-94    	E.PETIT	   	Add display control init                      *
;* 04-02-94    	E.PETIT	   	Manage banner display                         *
;* 21-02-94    	E.PETIT	   	Add plot color                                *
;* 25-02-94    	E.PETIT	   	Add test before plotting null profile         * 
;* 10-03-94    	E.PETIT	   	Add case for print                            *
;* 14-03-94    	N.MORISSET  Add dispersion calibration processing             *
;* 17-03-94    	E.PETIT  	Print trt suite                               *
;* 22-03-94    	E.PETIT  	Add Overplot                                  *
;* 13-04-94    	E.PETIT  	Add plot_sz management                        *
;* 18-04-94    	E.PETIT  	Add min/max                                   *
;* 24-05-94    	E.PETIT  	Enhance box size (print)                      *
;* 07-09-94    	E.PETIT  	Banner display PB                             *
;*                                                                            *
;******************************************************************************


;***
;##############################################################################
;#Procedure  name  : ql_update_banner                                         #
;#                                                                            #
;#Author           : Emmanuel PETIT                                           #
;#Language         : IDL                                                      #
;#Purpose          : Update banner with stat values                           #
;#Creation date    : 04-02-94                                                 #
;#Update date      :                                                          #
;#External modules :                                                          #
;#                                                                            #
;#Call sequence    : update_banner, mode, err                                 #
;#                                                                            #
;#Arguments        :mode: input (0:image, 100:profile)                        #
;#                  err : output 0 if ok                                      #
;#Description      :                                                          #
;#                                                                            #
;##############################################################################
;***  
PRO ql_update_banner, mode,err   

  ;============================================================================
  ;                       Common Block in use
  ;============================================================================
  COMMON widget_id_com
  COMMON curr_data_i_com
  COMMON curr_data_p_com
  COMMON flag_com
  COMMON const_com
  COMMON color_com

  ;============================================================================
  ;                       Initialization
  ;============================================================================
   err = 0
  
  ;============================================================================
  ;                       Processing 
  ;============================================================================
  

  CASE mode OF 
    000: BEGIN
          STRPUT ,i_ban_p_cur_str,'X (dev)       ', 00 
          STRPUT ,i_ban_p_cur_str,'Y (dev)       ', 14 
          STRPUT ,i_ban_p_cur_str,'X (data)      ', 28 
          STRPUT ,i_ban_p_cur_str,'Y (data)      ', 42 
          STRPUT ,i_ban_p_cur_str,'Data Value    ', 56 

          STRPUT ,i_ban_p_fix_str,'Minimun       ', 00 
          STRPUT ,i_ban_p_fix_str,'Maximum       ', 14 
          STRPUT ,i_ban_p_fix_str,'Mean          ', 28 
          STRPUT ,i_ban_p_fix_str,'Mediane       ', 42 
          STRPUT ,i_ban_p_fix_str,'Std Dev.      ', 56 
          STRPUT ,i_ban_p_fix_str,'Mode          ', 70

          WIDGET_CONTROL,i_ban_p_cur_lbl  , SET_VALUE=i_ban_p_cur_str
          WIDGET_CONTROL,i_ban_p_fix_lbl  , SET_VALUE=i_ban_p_fix_str

          str1 = STRING ('',FORMAT='(A14)') & STRPUT ,i_ban_d_fix_str, str1, 00 
          str2 = STRING ('',FORMAT='(A14)') & STRPUT ,i_ban_d_fix_str, str2, 14
          str3 = STRING ('',FORMAT='(A14)') & STRPUT ,i_ban_d_fix_str, str3, 28 
          str4 = STRING ('',FORMAT='(A14)') & STRPUT ,i_ban_d_fix_str, str4, 42
          str5 = STRING ('',FORMAT='(A14)') & STRPUT ,i_ban_d_fix_str, str5, 56 
          WIDGET_CONTROL,i_ban_d_fix_lbl  , SET_VALUE=i_ban_d_fix_str

          str1 = STRTRIM (STRING (curr_banner_i.min    ),2) & STRPUT ,i_ban_d_fix_str, str1, 00
          str2 = STRTRIM (STRING (curr_banner_i.max    ),2) & STRPUT ,i_ban_d_fix_str, str2, 14
          str3 = STRTRIM (STRING (curr_banner_i.average),2) & STRPUT ,i_ban_d_fix_str, str3, 28
          str4 = STRTRIM (STRING (curr_banner_i.mediane),2) & STRPUT ,i_ban_d_fix_str, str4, 42
          str5 = STRTRIM (STRING (curr_banner_i.rms    ),2) & STRPUT ,i_ban_d_fix_str, str5, 56  
          WIDGET_CONTROL,i_ban_d_cur_lbl  , SET_VALUE=i_ban_d_cur_str
          WIDGET_CONTROL,i_ban_d_fix_lbl  , SET_VALUE=i_ban_d_fix_str


          ; Restore line identification marks 
          ; ---------------------------------
          WSET, work_draw_back         		; switch to pixmap
          i=0
          WHILE (curr_banner_i.mark_line(i).lambda NE 0.0) DO BEGIN
             ydev=curr_banner_i.mark_line(i).lbl_y
             string= STRTRIM(curr_banner_i.mark_line(i).line_name,2)
       
             xx1 = curr_banner_i.mark_line(i).lambda    
             xx0 = xx1 - 0.0035 * (curr_dctrl_i.x.plot_max-curr_dctrl_i.x.plot_min)
             xx2 = xx1 + 0.0035 * (curr_dctrl_i.x.plot_max-curr_dctrl_i.x.plot_min)

             yy0 = curr_dctrl_i.y.plot_max+0.03 *(curr_dctrl_i.y.plot_max-curr_dctrl_i.y.plot_min)
             yy1 = curr_dctrl_i.y.plot_max+0.02 *(curr_dctrl_i.y.plot_max-curr_dctrl_i.y.plot_min)
             yy3 = curr_dctrl_i.y.plot_min + $
                 (FLOAT(ydev-FLOAT(curr_dctrl_i.y.offset))/FLOAT(curr_dctrl_i.y.plot_sz))* $
                  (curr_dctrl_i.y.plot_max-curr_dctrl_i.y.plot_min)
             yy2 = yy3 + 0.02 * (curr_dctrl_i.y.plot_max-curr_dctrl_i.y.plot_min)
  
             XA=[xx1, xx1, xx0, xx1, xx2, xx1]              
             YA=[yy1, yy2, yy2, yy3, yy2, yy2]
          
             PLOTS,XA(0:1),YA(0:1), /DATA
             POLYFILL,XA,YA, /DATA
             XYOUTS,xx1, yy0, string, ALIGNMENT=0.5, /DATA
            i  = i+1
          ENDWHILE
  
          WIDGET_CONTROL, work_draw, GET_VALUE=win_num
          WSET, win_num         
          ql_refresh, IMAGE, err

         END                          
 
    100: BEGIN
          STRPUT ,p_ban_p_cur_str,'X (data)      ', 00 
          STRPUT ,p_ban_p_cur_str,'Y (data)      ', 14 
          STRPUT ,p_ban_p_cur_str,'              ', 28 
          WIDGET_CONTROL,p_ban_p_cur_lbl  , SET_VALUE=p_ban_p_cur_str

          STRPUT ,p_ban_p_fix_str,'Minimun       ', 00 
          STRPUT ,p_ban_p_fix_str,'Maximum       ', 14 
          STRPUT ,p_ban_p_fix_str,'Mean          ', 28 
          STRPUT ,p_ban_p_fix_str,'Mediane       ', 42 
          STRPUT ,p_ban_p_fix_str,'Std Dev.      ', 56 
          STRPUT ,p_ban_p_fix_str,'Mode          ', 70
          WIDGET_CONTROL,p_ban_p_fix_lbl  , SET_VALUE=p_ban_p_fix_str

          str1 = STRING ('',FORMAT='(A14)') & STRPUT ,p_ban_d_fix_str, str1, 00 
          str2 = STRING ('',FORMAT='(A14)') & STRPUT ,p_ban_d_fix_str, str2, 14
          str3 = STRING ('',FORMAT='(A14)') & STRPUT ,p_ban_d_fix_str, str3, 28 
          str4 = STRING ('',FORMAT='(A14)') & STRPUT ,p_ban_d_fix_str, str4, 42
          str5 = STRING ('',FORMAT='(A14)') & STRPUT ,p_ban_d_fix_str, str5, 56 
          WIDGET_CONTROL,p_ban_d_fix_lbl  , SET_VALUE=p_ban_d_fix_str

          str1 = STRTRIM (STRING (curr_banner_p.min    ),2) & STRPUT ,p_ban_d_fix_str, str1, 00
          str2 = STRTRIM (STRING (curr_banner_p.max    ),2) & STRPUT ,p_ban_d_fix_str, str2, 14
          str3 = STRTRIM (STRING (curr_banner_p.average),2) & STRPUT ,p_ban_d_fix_str, str3, 28
          str4 = STRTRIM (STRING (curr_banner_p.mediane),2) & STRPUT ,p_ban_d_fix_str, str4, 42
          str5 = STRTRIM (STRING (curr_banner_p.rms    ),2) & STRPUT ,p_ban_d_fix_str, str5, 56  
          WIDGET_CONTROL,p_ban_d_cur_lbl  , SET_VALUE=p_ban_d_cur_str
          WIDGET_CONTROL,p_ban_d_fix_lbl  , SET_VALUE=p_ban_d_fix_str

          ; Restore line identification marks
          ; (If linear axis)
          ; ---------------------------------
          IF (curr_dctrl_p.x.type EQ 0 ) THEN BEGIN
            WSET, profile_draw_back         		; switch to pixmap
            i=0
            WHILE (curr_banner_p.mark_line(i).lambda NE 0.0) DO BEGIN
               ydev=curr_banner_p.mark_line(i).lbl_y
               string= STRTRIM(curr_banner_p.mark_line(i).line_name,2)
  
               xx1 = curr_banner_p.mark_line(i).lambda    
               xx0 = xx1 - 0.0035 * (curr_dctrl_p.x.plot_max-curr_dctrl_p.x.plot_min)
               xx2 = xx1 + 0.0035 * (curr_dctrl_p.x.plot_max-curr_dctrl_p.x.plot_min)
  
               yy0 = curr_dctrl_p.y.plot_max+0.03 * (curr_dctrl_p.y.plot_max-curr_dctrl_p.y.plot_min)
               yy1 = curr_dctrl_p.y.plot_max+0.02 * (curr_dctrl_p.y.plot_max-curr_dctrl_p.y.plot_min)
               yy3 = curr_dctrl_p.y.plot_min + $
                   (FLOAT(ydev-FLOAT(curr_dctrl_p.y.offset))/FLOAT(curr_dctrl_p.y.plot_sz))* $
                    (curr_dctrl_p.y.plot_max-curr_dctrl_p.y.plot_min)
               yy2 = yy3 + 0.02 * (curr_dctrl_p.y.plot_max-curr_dctrl_p.y.plot_min) 
  
               XA=[xx1, xx1, xx0, xx1, xx2, xx1]
               YA=[yy1, yy2, yy2, yy3, yy2, yy2]
     
               PLOTS,XA(0:1),YA(0:1), /DATA
               POLYFILL,XA,YA, /DATA
               XYOUTS,xx1, yy0, string, ALIGNMENT=0.5, /DATA
               i  = i+1
            ENDWHILE
          ENDIF

          WIDGET_CONTROL, profile_draw, GET_VALUE=win_num
          WSET, win_num         
          ql_refresh, PROFILE, err
         END
    101: BEGIN
          p_ban_p_cur_str = STRING('', FORMAT='(A70)')
          p_ban_d_cur_str = STRING('', FORMAT='(A70)')

          p_ban_p_fix_str = STRING('', FORMAT='(A84)')
          p_ban_d_fix_str = STRING('', FORMAT='(A84)')

          WIDGET_CONTROL,p_ban_p_cur_lbl, SET_VALUE=p_ban_p_cur_str
          WIDGET_CONTROL,p_ban_p_fix_lbl, SET_VALUE=p_ban_p_fix_str
          WIDGET_CONTROL,p_ban_d_cur_lbl, SET_VALUE=p_ban_d_cur_str
          WIDGET_CONTROL,p_ban_d_fix_lbl, SET_VALUE=p_ban_d_fix_str
         END
    102: BEGIN
         END
    103: BEGIN
         END 
    110: BEGIN
          ; No stat values if over plot 
          WIDGET_CONTROL,p_ban_p_fix_lbl  , SET_VALUE=''
          WIDGET_CONTROL,p_ban_d_cur_lbl  , SET_VALUE=''
          WIDGET_CONTROL,p_ban_d_fix_lbl  , SET_VALUE=''
         END
    ELSE:
  ENDCASE
END

;***
;##############################################################################
;#Procedure  name  : ql_draw_multi_axis                                       #
;#                                                                            #
;#Author           : Emmanuel PETIT                                           #
;#Language         : IDL                                                      #
;#Purpose          : Customize axis aspect according to control structure     #
;#Creation date    : 26 01 94                                                 #
;#Update date      :                                                          #
;#External modules :                                                          #
;#                                                                            #
;#Call sequence    :                                                          #
;#                                                                            #
;#Arguments        :ctrl : display control structure                          #
;#                  mode : display mode  from 0 to 99                         #
;#                  data : data to be plot (mode 100 only)                    #
;#                  err  : error status                                       #
;#Description      :                                                          #
;#                                                                            #
;##############################################################################
;***  
PRO ql_draw_multi_axis ,mode, data, ctrl, index, err
  ;============================================================================
  ;                       Processing 
  ;============================================================================

  yplotmax = max(data(index,*), xmax, min=yplotmin) 
  IF (yplotmax EQ yplotmin) THEN yplotmax = yplotmin + 1
 

  cmd_str = 'PLOT,' +    '['+ STRING(ctrl.x.plot_min) + ','              + $
                              STRING(ctrl.x.plot_max)                    + $
                         '],'                                            + $
                        '['                                              + $
                              STRING(yplotmin) + ','                     + $
                              STRING(yplotmax)                           + $
                        ']'                                              + $
            ',XSTYLE=' + STRING(ctrl.x.style)                            + $ 
            ',YSTYLE=' + STRING(ctrl.y.style)                            + $ 
            ',XTICKLEN= FLOAT(' + STRING(ctrl.x.tick_len)+')/100'        + $ 
            ',YTICKLEN= FLOAT(' + STRING(ctrl.y.tick_len)+')/100'        + $ 
            ',XGRIDSTYLE=' + STRING(ctrl.grid_style)                     + $
            ',YGRIDSTYLE=' + STRING(ctrl.grid_style)                     + $
            ',TITLE=' + "'" + STRTRIM(ctrl.title,2)     + "'"            + $ 
            ',XTITLE=' + "'" + STRTRIM(ctrl.x.comment,2) + "'"           + $ 
            ',YTITLE=' + "'" + STRTRIM(ctrl.y.comment,2) + "'"           + $
            ',XTICKS=' + STRING(ctrl.x.nb_tick)                          + $
            ',XMINOR=' + STRING(ctrl.x.nb_minor)                         + $ 
            ',YTICKS=' + STRING(ctrl.y.nb_tick)                          + $
            ',YMINOR=' + STRING(ctrl.y.nb_minor)                         + $ 
            ',/NODATA'                                                  

  ret = EXECUTE (cmd_str) 
END

;***
;##############################################################################
;#Procedure  name  : ql_draw_axis                                             #
;#                                                                            #
;#Author           : Emmanuel PETIT                                           #
;#Language         : IDL                                                      #
;#Purpose          : Customize axis aspect according to control structure     #
;#Creation date    : 19 01 94                                                 #
;#Update date      :                                                          #
;#External modules :                                                          #
;#                                                                            #
;#Call sequence    :                                                          #
;#                                                                            #
;#Arguments        :ctrl : display control structure                          #
;#                  mode : display mode  from 0 to 99                         #
;#                  data : data to be plot (mode 100 only)                    #
;#                  err  : error status                                       #
;#Description      :                                                          #
;#                                                                            #
;##############################################################################
;***  
PRO ql_draw_axis ,mode, ctrl, data, err
  ;============================================================================
  ;                       Common Block in use
  ;============================================================================
  COMMON curr_data_p_com
  COMMON curr_data_i_com
  COMMON color_com

  ;============================================================================
  ;                       Processing 
  ;============================================================================

  cmd_str = 'PLOT,'   + $
            '['+ STRING(ctrl.x.plot_min) + ',' +STRING(ctrl.x.plot_max) + '],' + $
            '['+ STRING(ctrl.y.plot_min) + ',' +STRING(ctrl.y.plot_max) + '] ' 

  IF (ctrl.x.type EQ 0) AND (ctrl.y.type EQ 0) THEN BEGIN
  cmd_str =  cmd_str   + $
            ',XTICKS=' + STRING(ctrl.x.nb_tick)                          + $
            ',XMINOR=' + STRING(ctrl.x.nb_minor)                         + $
            ',YTICKS=' + STRING(ctrl.y.nb_tick)                          + $
            ',YMINOR=' + STRING(ctrl.y.nb_minor)             
  ENDIF ELSE BEGIN
    IF (ctrl.x.type EQ 1 ) THEN BEGIN
      cmd_str = cmd_str + ',/XLOG'                                       + $
            ',YTICKS=' + STRING(ctrl.y.nb_tick)                          + $
            ',YMINOR=' + STRING(ctrl.y.nb_minor)                       
    ENDIF 
    IF (ctrl.y.type EQ 1 ) THEN BEGIN
      cmd_str = cmd_str + ',/YLOG'                                       + $
            ',XTICKS=' + STRING(ctrl.x.nb_tick)                          + $
            ',XMINOR=' + STRING(ctrl.x.nb_minor)                        
    ENDIF
  ENDELSE
  cmd_str = cmd_str +  $
            ',POSITION =['+STRING(ctrl.x.offset-1) + ','                 + $
                           STRING(ctrl.y.offset-1) + ','                 + $
                           STRING(ctrl.x.offset-1+ctrl.x.plot_sz-1) + ','+ $
                           STRING(ctrl.y.offset-1+ctrl.y.plot_sz-1)      + $   
                      ']'                                                + $
            ',XSTYLE=' + STRING(ctrl.x.style)                            + $ 
            ',YSTYLE=' + STRING(ctrl.y.style)                            + $ 
            ',XTICKLEN= FLOAT(' + STRING(ctrl.x.tick_len)+')/100'        + $ 
            ',YTICKLEN= FLOAT(' + STRING(ctrl.y.tick_len)+')/100'        + $ 
            ',XGRIDSTYLE=' + STRING(ctrl.grid_style)                     + $
            ',YGRIDSTYLE=' + STRING(ctrl.grid_style)                     + $
            ',XTITLE=' + "'" + STRTRIM(ctrl.x.comment,2) + "'"           + $ 
            ',YTITLE=' + "'" + STRTRIM(ctrl.y.comment,2) + "'"           + $
            ',/NODATA'                                                   + $
            ',/DEVICE'                                                   + $
            ',/NOERASE'

  XYOUTS ,ctrl.x.offset+(ctrl.x.plot_sz/2)-100                  , $
          ctrl.y.offset+ctrl.y.nb_dot + 30                      , $
          STRTRIM(ctrl.title,2)                                 , $
          /DEVICE                                               , $
          CHARSIZE=1.4                                          , $
          CHARTHICK=1.9

  ret = EXECUTE (cmd_str) 
END

;***
;##############################################################################
;#Function  name   : ql_display_data                                          #
;#                                                                            #
;#Author           : Emmanuel PETIT                                           #
;#Language         : IDL                                                      #
;#Purpose          : Display given set of data according to specified mode    #
;#Creation date    : December 1993                                            #
;#Update date      : 18-01-94    	E.PETIT	   Display control management #
;#External modules :                                                          #
;#                                                                            #
;#Call sequence    :                                                          #
;#                                                                            #
;#Arguments        :                                                          #
;#                                                                            #
;#Description      :                                                          #
;#                                                                            #
;##############################################################################
;***  
FUNCTION ql_display_data, data, mode ,ctrl,  err
  ;============================================================================
  ;                       Common Block in use
  ;============================================================================
  COMMON widget_id_com
  COMMON const_com
  COMMON color_com
  COMMON curr_data_p_com
  COMMON curr_data_i_com
  COMMON print_com
  COMMON dispcal_com
  COMMON load_flg_com
  COMMON overp_com
  COMMON stack_com

  ;============================================================================
  ;                       Initialization
  ;============================================================================
  text_value = STRARR (15) 
  ret = 0
  ;============================================================================
  ;                       Processing 
  ;============================================================================
  WIDGET_CONTROL, /HOURGLASS

  !P.MULTI=0
  CASE mode OF    
    ; Data display as image in working area
    ; -------------------------------------
    000: BEGIN 	         
           ; Switch to concerned window
           ; --------------------------                             
           WIDGET_CONTROL, work_draw, GET_VALUE=win_num
           WIDGET_CONTROL, work_draw, SET_DRAW_VIEW=[0,0]
           WSET, win_num         
           ERASE

           ; Display data               
           ; ------------
           newdata=BYTSCL(data,top=max_nb_color)
           newdata=BYTSCL(newdata,min=color_min,max=color_max,top=max_nb_color)
           TV, newdata, ctrl.x.offset-1, ctrl.y.offset-1 	
           
           ; Display contour if asked 
           ; ------------------------
           IF (ctrl.contour_flg NE 0) THEN BEGIN
             CONTOUR, data                                        , $
                      POSITION=[ctrl.x.offset-1                   , $
                                ctrl.y.offset-1                   , $
                                ctrl.x.offset-1+ctrl.x.plot_sz-1  , $ 
                                ctrl.y.offset-1+ctrl.y.plot_sz-1] , $
                      XSTYLE    = 5                               , $
                      YSTYLE    = 5                               , $
                      NLEVELS   = ctrl.contour_flg                , $
                      /NOERASE                                    , $
                      /DEVICE
           ENDIF

           ; Display Axis
           ; ------------
           ql_draw_axis, mode, ctrl, data, err

           ; store image in pixmap
           ; ---------------------
           WSET, work_draw_back
           DEVICE, COPY=[0,0,IMAGE_X_SZ,IMAGE_Y_SZ,0,0,win_num]
           WSET, win_num
         END
    
    ; Data display as profile in profile area
    ; ---------------------------------------
    100: BEGIN 						; 1 parameter
           ; Switch to concerned window
           ; --------------------------                             
           WIDGET_CONTROL, profile_draw, GET_VALUE=win_num;  
           WIDGET_CONTROL, profile_draw, SET_DRAW_VIEW=[0,0]
           WSET, win_num         
           ERASE

           ; Update stat values
           ; ------------------
           ql_get_stat, data(curr_dctrl_p.x.index_min:curr_dctrl_p.x.index_max),PROFILE, err

           ; Display Axis
           ; ------------
           ql_draw_axis, mode, ctrl, data, err

           ; Display data
           ; ------------
           cmd_str = 'OPLOT, curr_x_p, data'          + $
                      ', COLOR=' + STRING(ctrl.color) + $          
                      ', PSYM =' + STRING(ctrl.symbol)
           ret = EXECUTE (cmd_str) 
           

           ; Visualize dots if less than 100
           ; -------------------------------
           IF ( ctrl.x.index_max-ctrl.x.index_min LT 100) THEN  BEGIN
             symb  = ctrl.symbol
             color = ctrl.color 
             ctrl.symbol = 1
             ctrl.color  = white
             ret=ql_display_data(data,120,ctrl,err)
             ctrl.symbol = symb
             ctrl.color  = color
           ENDIF
  
           ; store image in pixmap
           ; ---------------------
           WSET, profile_draw_back
           DEVICE, COPY=[0,0,PROFILE_X_SZ,PROFILE_Y_SZ,0,0,win_num]
           WSET, win_num
         END   

    101: BEGIN		   				; 2 parameters
           ; Switch to concerned window
           ; --------------------------                             
           WIDGET_CONTROL, profile_draw, GET_VALUE=win_num;  
           WIDGET_CONTROL, profile_draw, SET_DRAW_VIEW=[0,0]
           WSET, win_num         
           ERASE
           !P.MULTI=[0,2,1]

           ; Display data
           ; ------------
           FOR i=0,1 DO BEGIN
             ql_draw_multi_axis, mode, data, ctrl, i, err
             OPLOT, curr_x_p, data(i,*), COLOR=MULTI_COLOR(i)
           ENDFOR 

           ; Clear Banner
           ; ------------
           WIDGET_CONTROL,p_ban_p_cur_lbl  , SET_VALUE=''
           WIDGET_CONTROL,p_ban_p_fix_lbl  , SET_VALUE=''
           WIDGET_CONTROL,p_ban_d_cur_lbl  , SET_VALUE=''
           WIDGET_CONTROL,p_ban_d_fix_lbl  , SET_VALUE=''

           ; store image in pixmap
           ; ---------------------
           WSET, profile_draw_back
           DEVICE, COPY=[0,0,PROFILE_X_SZ ,PROFILE_Y_SZ ,0,0, win_num]
           WSET, win_num
         END   

    102: BEGIN						; 4 parameters
           ; Switch to concerned window
           ; --------------------------                             
           WIDGET_CONTROL, profile_draw, GET_VALUE=win_num;  
           WIDGET_CONTROL, profile_draw, SET_DRAW_VIEW=[0,0]
           WSET, win_num         
           ERASE
           !P.MULTI=[0,4,1]
            
           ; Display data
           ; ------------
           FOR i=0,3 DO BEGIN
             ql_draw_multi_axis, mode, data, ctrl, i, err
             OPLOT, curr_x_p, data(i,*), COLOR=MULTI_COLOR(i)
           ENDFOR 

           ; Clear Banner
           ; ------------
           WIDGET_CONTROL,p_ban_p_cur_lbl  , SET_VALUE=''
           WIDGET_CONTROL,p_ban_p_fix_lbl  , SET_VALUE=''
           WIDGET_CONTROL,p_ban_d_cur_lbl  , SET_VALUE=''
           WIDGET_CONTROL,p_ban_d_fix_lbl  , SET_VALUE=''

           ; store image in pixmap
           ; ---------------------
           WSET, profile_draw_back
           DEVICE, COPY=[0,0,PROFILE_X_SZ,PROFILE_Y_SZ ,0,0, win_num]
           WSET, win_num
         END   
 
    103: BEGIN						; 5 parameters
           ; Switch to concerned window
           ; --------------------------                             
           WIDGET_CONTROL, profile_draw, GET_VALUE=win_num;  
           WIDGET_CONTROL, profile_draw, SET_DRAW_VIEW=[0,0]
           WSET, win_num         
           ERASE
           !P.MULTI=[0,5,1]

           ; Display data
           ; ------------
           FOR i=0,4 DO BEGIN
             ql_draw_multi_axis, mode, data, ctrl, i, err
             OPLOT, curr_x_p, data(i,*), COLOR=MULTI_COLOR(i)
           ENDFOR 

           ; Clear Banner
           ; ------------
           WIDGET_CONTROL,p_ban_p_cur_lbl  , SET_VALUE=''
           WIDGET_CONTROL,p_ban_p_fix_lbl  , SET_VALUE=''
           WIDGET_CONTROL,p_ban_d_cur_lbl  , SET_VALUE=''
           WIDGET_CONTROL,p_ban_d_fix_lbl  , SET_VALUE=''

           ; store image in pixmap
           ; ---------------------
           WSET, profile_draw_back
           DEVICE, COPY=[0,0,PROFILE_X_SZ,PROFILE_Y_SZ ,0,0, win_num]
           WSET, win_num
         END   


    ; Over Plot Profiles
    ; -------------------
    110: BEGIN 

           ; Master plot: Axis definition
           ; ----------------------------
           ; plot master
           WIDGET_CONTROL, profile_draw, GET_VALUE=win_num;  
           ret = ql_display_data(overp_data(0,0:overp_sza (0)-1) , $
                                 100                             , $ 
                                 ctrl                            , $
                                 err)

           ; Overplot of other profile on master profile
           ; --------------------------------------------
           FOR i=1, -(load_flag_p)-1 DO BEGIN
             ; Init X values
             ; -------------
             X = FINDGEN (overp_sza (i))
             tmp_ctrl  = stack_hd.p(overp_indexes (i)).display_ctrl
             X = tmp_ctrl.x.min+X*(tmp_ctrl.x.max-tmp_ctrl.x.min)/(overp_sza(i)-1)
             tmp_data = data(i,0:overp_sza(i)-1)

             ; Build request
             ; -------------
             cmd_str = 'OPLOT, X, tmp_data'           + $
                       ', COLOR=' + STRING(tmp_ctrl.color) + $          
                       ', PSYM =' + STRING(tmp_ctrl.symbol)
             ret = EXECUTE (cmd_str) 

             ; Visualize dots if less than 100
             ; -------------------------------
             IF ( tmp_ctrl.x.index_max-tmp_ctrl.x.index_min LT 100) THEN  BEGIN
               symb  = tmp_ctrl.symbol
               color = tmp_ctrl.color 
               tmp_ctrl.symbol = 1
               tmp_ctrl.color  = white
               save_x_p = curr_x_p
               curr_x_p = X
               ret = ql_display_data(tmp_data, 120, tmp_ctrl , err)
               tmp_ctrl.symbol = symb
               tmp_ctrl.color  = color
               curr_x_p = save_x_p 
             ENDIF
           ENDFOR

           ; store image in pixmap
           ; ---------------------
           WSET, profile_draw_back
           DEVICE, COPY=[0,0,PROFILE_X_SZ,PROFILE_Y_SZ,0,0,win_num]
           WSET, win_num
     END   

    ; Data overploted 
    ; --------------
    120: BEGIN
           ; Switch to concerned window
           ; --------------------------                             
           WIDGET_CONTROL, profile_draw, GET_VALUE=win_num;  
           WSET, win_num         

           ; Display data
           ; ------------
           cmd_str = 'OPLOT, curr_x_p, data'          + $
                      ', COLOR=' + STRING(ctrl.color) + $          
                      ', PSYM =' + STRING(ctrl.symbol)
           ret = EXECUTE (cmd_str) 
           
           ; store image in pixmap
           ; ---------------------
           WSET, profile_draw_back
           DEVICE, COPY=[0,0,PROFILE_X_SZ,PROFILE_Y_SZ,0,0,win_num]
           WSET, win_num
         END   


      300: BEGIN
           ; Switch to concerned window
           ; --------------------------                             
           WIDGET_CONTROL, profile_draw, GET_VALUE=win_num;  
           WSET, win_num         

           ; Display data
           ; ------------
           cmd_str = 'OPLOT, xfit, data'              + $
                      ', COLOR=' + STRING(ctrl.color) + $          
                      ', PSYM =' + STRING(ctrl.symbol)
           ret = EXECUTE (cmd_str) 

           ; store image in pixmap
           ; ---------------------
           WSET, profile_draw_back
           DEVICE, COPY=[0,0,PROFILE_X_SZ,PROFILE_Y_SZ,0,0, win_num]
           WSET, win_num
           ql_refresh, PROFILE
         END

    ; Data display as profile in PS file
    ; ----------------------------------
    1000: BEGIN

           ; print  axis
           ; ------------
           cmd_str = 'PLOT,'                                                      + $
                     '['+ STRING(ctrl.x.plot_min)+','+STRING(ctrl.x.plot_max)+'],'+ $
                     '['+STRING(ctrl.y.plot_min) +','+STRING(ctrl.y.plot_max)+']'

                      IF (ctrl.x.type EQ 0) AND (ctrl.y.type EQ 0) THEN BEGIN
                      cmd_str =  cmd_str   + $
                                ',XTICKS=' + STRING(ctrl.x.nb_tick)                          + $
                                ',XMINOR=' + STRING(ctrl.x.nb_minor)                         + $
                                ',YTICKS=' + STRING(ctrl.y.nb_tick)                          + $
                                ',YMINOR=' + STRING(ctrl.y.nb_minor)             
                      ENDIF ELSE BEGIN
                        IF (ctrl.x.type EQ 1 ) THEN BEGIN
                          cmd_str = cmd_str + ',/XLOG'                                       + $
                                ',YTICKS=' + STRING(ctrl.y.nb_tick)                          + $
                                ',YMINOR=' + STRING(ctrl.y.nb_minor)                       
                        ENDIF 
                        IF (ctrl.y.type EQ 1 ) THEN BEGIN
                          cmd_str = cmd_str + ',/YLOG'                                       + $
                                ',XTICKS=' + STRING(ctrl.x.nb_tick)                          + $
                                ',XMINOR=' + STRING(ctrl.x.nb_minor)                        
                        ENDIF
                      ENDELSE
           cmd_str = cmd_str +  $
                     ',XSTYLE=' + STRING(ctrl.x.style)                            + $ 
                     ',YSTYLE=' + STRING(ctrl.y.style)                            + $ 
                     ',XTICKLEN= FLOAT(' + STRING(ctrl.x.tick_len)+')/100'        + $ 
                     ',YTICKLEN= FLOAT(' + STRING(ctrl.y.tick_len)+')/100'        + $ 
                     ',XGRIDSTYLE=' + STRING(ctrl.grid_style)                     + $
                     ',YGRIDSTYLE=' + STRING(ctrl.grid_style)                     + $
                     ',XTITLE=' + "'" + STRTRIM(ctrl.x.comment,2) + "'"           + $ 
                     ',YTITLE=' + "'" + STRTRIM(ctrl.y.comment,2) + "'"           + $
                     ',/NODATA'                                                   + $
                     ',/DEVICE'                                                   + $
                     ',/NOERASE'

           ret = EXECUTE (cmd_str) 

           ; Display data
           ; ------------
           cmd_str = 'OPLOT, curr_x_p, data,COLOR =' + STRING(ctrl.color)
           ;cmd_str = 'OPLOT, curr_x_p, data, PSYM =' + STRING(ctrl.symbol)
           ret = EXECUTE (cmd_str) 
            
           ; -------------------------
           ; line identification marks
           ; (If linear axis)
           ; -------------------------
           IF (curr_dctrl_p.x.type EQ 0 AND curr_dctrl_p.y.type EQ 0) THEN BEGIN
             i=0
             WHILE (curr_banner_p.mark_line(i).lambda NE 0.0) DO BEGIN
               ydev=curr_banner_p.mark_line(i).lbl_y
               string= STRTRIM(curr_banner_p.mark_line(i).line_name,2)

               xx1 = curr_banner_p.mark_line(i).lambda    
               xx0 = xx1 - 0.0035 * (curr_dctrl_p.x.plot_max-curr_dctrl_p.x.plot_min)
               xx2 = xx1 + 0.0035 * (curr_dctrl_p.x.plot_max-curr_dctrl_p.x.plot_min)

               yy0 = curr_dctrl_p.y.plot_max+0.03 * (curr_dctrl_p.y.plot_max-curr_dctrl_p.y.plot_min)
               yy1 = curr_dctrl_p.y.plot_max+0.02 * (curr_dctrl_p.y.plot_max-curr_dctrl_p.y.plot_min)
               yy3 = curr_dctrl_p.y.plot_min + $
                   (FLOAT(ydev-FLOAT(curr_dctrl_p.y.offset))/FLOAT(curr_dctrl_p.y.plot_sz))* $
                    (curr_dctrl_p.y.plot_max-curr_dctrl_p.y.plot_min)
               yy2 = yy3 + 0.02 * (curr_dctrl_p.y.plot_max-curr_dctrl_p.y.plot_min)

               XA=[xx1, xx1, xx0, xx1, xx2, xx1]
               YA=[yy1, yy2, yy2, yy3, yy2, yy2]
   
               PLOTS,XA(0:1),YA(0:1), /DATA
               POLYFILL,XA,YA, /DATA
               XYOUTS,xx1, yy0, string, ALIGNMENT=0.5, /DATA
               i  = i+1
             ENDWHILE
           ENDIF

           ; Stat Values
           ; -----------
           x = (PG_XL_MARGIN              ) * !D.X_PX_CM/10.0
           y = (PG_YB_MARGIN + szy + 14.0  ) * !D.Y_PX_CM/10.0
           XYOUTS, x, y,STRMID(p_ban_p_fix_str,0, 70), /DEVICE

           x = (PG_XL_MARGIN              ) * !D.X_PX_CM/10.0
           y = (PG_YB_MARGIN + szy + 11.0  ) * !D.Y_PX_CM/10.0
           XYOUTS, x, y,STRMID (p_ban_d_fix_str, 0, 70), /DEVICE                

           ; Header Info and Title
           ; ---------------------
           X    =  !D.X_PX_CM * $
                   [(PG_XL_MARGIN        )/10.0  , $
                    (PG_XL_MARGIN  + 170.0)/10.0 , $
                    (PG_XL_MARGIN  + 170.0)/10.0 , $
                    (PG_XL_MARGIN         )/10.0 , $
                    (PG_XL_MARGIN         )/10.0]
           Y    =  !D.Y_PX_CM * $
                   [(PG_YB_MARGIN+szy+24.0)/10.0 , $
                    (PG_YB_MARGIN+szy+24.0)/10.0 , $
                    (PG_YB_MARGIN+szy+65.0)/10.0 , $
                    (PG_YB_MARGIN+szy+65.0)/10.0 , $
                    (PG_YB_MARGIN+szy+24.0)/10.0]
           PLOTS, X, Y, /DEVICE

           Y    =  !D.Y_PX_CM * $
                   [(PG_YB_MARGIN+szy+65.0)/10.0 , $
                    (PG_YB_MARGIN+szy+65.0)/10.0 , $
                    (PG_YB_MARGIN+szy+70.0)/10.0 , $
                    (PG_YB_MARGIN+szy+70.0)/10.0 , $
                    (PG_YB_MARGIN+szy+65.0)/10.0]
           PLOTS, X, Y, /DEVICE

           x = (PG_XL_MARGIN+57.0)*!D.X_PX_CM/10.0 
           y = (PG_YB_MARGIN + szy + 67.0) * !D.Y_PX_CM/10.0  
           XYOUTS, x, y,STRTRIM(ctrl.title,2), /DEVICE

           ql_format_hd, curr_header_p, text_value, err
           FOR i=0, 10 DO BEGIN
             x = (PG_XL_MARGIN + 2.0)*!D.X_PX_CM/10.0 
             y = (PG_YB_MARGIN + szy + 60.0 - i*3.0) * !D.Y_PX_CM/10.0  
             XYOUTS, x, y, text_value(i), /DEVICE
           ENDFOR

           j=0
           FOR i=11,N_ELEMENTS(text_value)-1 DO BEGIN
             x = (PG_XL_MARGIN+80.0)*!D.X_PX_CM/10.0 
             y = (PG_YB_MARGIN + szy + 60.0 - j*3.0) * !D.Y_PX_CM/10.0  
             XYOUTS, x, y, text_value(i), /DEVICE
             j = j+1
           ENDFOR
         END

    ; Data display as Multi profile in PS file
    ; ----------------------------------------
    1110: BEGIN
           ; Master print: Axis definition
           ; -----------------------------

           ; print  axis
           ; ------------
           cmd_str = 'PLOT,'                                                      + $
                    '['+ STRING(ctrl.x.plot_min)+','+STRING(ctrl.x.plot_max)+'],' + $
                    '['+STRING(ctrl.y.plot_min) +','+STRING(ctrl.y.plot_max)+']'
           IF (ctrl.x.type EQ 0) AND (ctrl.y.type EQ 0) THEN BEGIN
           cmd_str =  cmd_str   + $
                     ',XTICKS=' + STRING(ctrl.x.nb_tick)                          + $
                     ',XMINOR=' + STRING(ctrl.x.nb_minor)                         + $
                     ',YTICKS=' + STRING(ctrl.y.nb_tick)                          + $
                     ',YMINOR=' + STRING(ctrl.y.nb_minor)             
           ENDIF ELSE BEGIN
             IF (ctrl.x.type EQ 1 ) THEN BEGIN
               cmd_str = cmd_str + ',/XLOG'                                       + $
                     ',YTICKS=' + STRING(ctrl.y.nb_tick)                          + $
                     ',YMINOR=' + STRING(ctrl.y.nb_minor)                       
             ENDIF 
             IF (ctrl.y.type EQ 1 ) THEN BEGIN
               cmd_str = cmd_str + ',/YLOG'                                       + $
                     ',XTICKS=' + STRING(ctrl.x.nb_tick)                          + $
                     ',XMINOR=' + STRING(ctrl.x.nb_minor)                        
             ENDIF
           ENDELSE
           cmd_str = cmd_str +  $
                     ',XSTYLE=' + STRING(ctrl.x.style)                            + $ 
                     ',YSTYLE=' + STRING(ctrl.y.style)                            + $ 
                     ',XTICKLEN= FLOAT(' + STRING(ctrl.x.tick_len)+')/100'        + $ 
                     ',YTICKLEN= FLOAT(' + STRING(ctrl.y.tick_len)+')/100'        + $ 
                     ',XGRIDSTYLE=' + STRING(ctrl.grid_style)                     + $
                     ',YGRIDSTYLE=' + STRING(ctrl.grid_style)                     + $
                     ',XTITLE=' + "'" + STRTRIM(ctrl.x.comment,2) + "'"           + $ 
                     ',YTITLE=' + "'" + STRTRIM(ctrl.y.comment,2) + "'"           + $
                     ',/NODATA'                                                   + $
                     ',/DEVICE'                                                   + $
                     ',/NOERASE'
           ret = EXECUTE (cmd_str) 

           ; plot master
           ; -----------
;           OPLOT, curr_x_p, overp_data(0,0:overp_sza (0)-1)
           OPLOT, curr_x_p, overp_data(0,0:overp_sza (0)-1), COLOR=ctrl.color
 
           ; Overplot of other profile on master profile
           ; --------------------------------------------
           FOR i=1, -(load_flag_p)-1 DO BEGIN
             X = FINDGEN (overp_sza (i))
             tmp_ctrl  = stack_hd.p(overp_indexes (i)).display_ctrl
             X = tmp_ctrl.x.min+X*(tmp_ctrl.x.max-tmp_ctrl.x.min)/(overp_sza(i)-1)
             tmp_data = data(i,0:overp_sza(i)-1)

             ; Build request
             ; -------------
             ;cmd_str = 'OPLOT,X,tmp_data,LINESTYLE='+STRING(i)+',PSYM =' + STRING(ctrl.symbol)
             cmd_str = 'OPLOT,X,tmp_data,COLOR =' +STRING(tmp_ctrl.color)
             ret = EXECUTE (cmd_str) 
         ENDFOR


           ; Header Info and Title
           ; ---------------------
           X    =  !D.X_PX_CM * $
                   [(PG_XL_MARGIN        )/10.0  , $
                    (PG_XL_MARGIN  + 170.0)/10.0 , $
                    (PG_XL_MARGIN  + 170.0)/10.0 , $
                    (PG_XL_MARGIN         )/10.0 , $
                    (PG_XL_MARGIN         )/10.0]
           Y    =  !D.Y_PX_CM * $
                   [(PG_YB_MARGIN+szy+24.0)/10.0 , $
                    (PG_YB_MARGIN+szy+24.0)/10.0 , $
                    (PG_YB_MARGIN+szy+65.0)/10.0 , $
                    (PG_YB_MARGIN+szy+65.0)/10.0 , $
                    (PG_YB_MARGIN+szy+24.0)/10.0]
           PLOTS, X, Y, /DEVICE

           Y    =  !D.Y_PX_CM * $
                   [(PG_YB_MARGIN+szy+65.0)/10.0 , $
                    (PG_YB_MARGIN+szy+65.0)/10.0 , $
                    (PG_YB_MARGIN+szy+70.0)/10.0 , $
                    (PG_YB_MARGIN+szy+70.0)/10.0 , $
                    (PG_YB_MARGIN+szy+65.0)/10.0]
           PLOTS, X, Y, /DEVICE

           x = (PG_XL_MARGIN+57.0)*!D.X_PX_CM/10.0 
           y = (PG_YB_MARGIN + szy + 67.0) * !D.Y_PX_CM/10.0  
           XYOUTS, x, y,'Profiles Overplot', /DEVICE

           FOR i=0, -(load_flag_p)-1 DO BEGIN
             tmp_ctrl  = stack_hd.p(overp_indexes (i)).display_ctrl
             X    =  !D.X_PX_CM * $
                     [(PG_XL_MARGIN  + 2.0  )/10.0  , $
                      (PG_XL_MARGIN  + 17.0 )/10.0 , $
                      (PG_XL_MARGIN  + 2.0  )/10.0]
             Y    =  !D.Y_PX_CM * $
                     [(PG_YB_MARGIN + szy + 60.0 - i*3.0)/10.0 , $
                      (PG_YB_MARGIN + szy + 60.0 - i*3.0)/10.0 , $
                      (PG_YB_MARGIN + szy + 60.0 - i*3.0)/10.0 ]
;             PLOTS, X, Y,LINESTYLE=i, /DEVICE
              PLOTS, X, Y,COLOR=tmp_ctrl.color, /DEVICE

             x = (PG_XL_MARGIN + 19.0)*!D.X_PX_CM/10.0 
             y = (PG_YB_MARGIN + szy + 60.0 - i*3.0) * !D.Y_PX_CM/10.0  
              str = stack_hd.p(overp_indexes (i)).display_ctrl.title
             XYOUTS, x, y, str,  color=tmp_ctrl.color,/DEVICE
           ENDFOR
         END


    ; Data display as image in PS file
    ; ---------------------------------
    2000: BEGIN 	         
           ; Data
           ; ----
           IF (lp_dat_flg EQ 1) THEN BEGIN
             newdata=BYTSCL(data,top=!D.N_COLORS)
             newdata=BYTSCL(newdata                                , $
                            MIN = color_min                        , $
                            MAX = (color_max*(!D.N_COLORS-1))/200.0, $
                            TOP =!D.N_COLORS-1)
             TV, newdata          , $
                 PG_XL_MARGIN/10.0, $
                 PG_YB_MARGIN/10.0, $
                 XSIZE = szx/10.0 , $
                 YSIZE = szy/10.0 , $
                 /CENTIMETERS       
           ENDIF

           ; Axis
           ; ----
           cmd_str = 'PLOT'
           cmd_str = cmd_str  +  ','                                              + $
                                 '['+  STRING(ctrl.x.plot_min) + ','              + $
                                       STRING(ctrl.x.plot_max)                    + $
                                 ']' + ','                                        + $
                                 '[' + STRING(ctrl.y.plot_min) + ','              + $
                                       STRING(ctrl.y.plot_max)                    + $
                                 ']'                                              + $
                     ',XSTYLE    =' + STRING(ctrl.x.style)                        + $ 
                     ',YSTYLE    =' + STRING(ctrl.y.style)                        + $ 
                     ',XTICKLEN  = FLOAT(' + STRING(ctrl.x.tick_len)+')/100'      + $ 
                     ',YTICKLEN  = FLOAT(' + STRING(ctrl.y.tick_len)+')/100'      + $ 
                     ',XGRIDSTYLE=' + STRING(ctrl.grid_style)                     + $
                     ',YGRIDSTYLE=' + STRING(ctrl.grid_style)                     + $
                     ',XTITLE    =' + "'" + STRTRIM(ctrl.x.comment,2) + "'"       + $ 
                     ',YTITLE    =' + "'" + STRTRIM(ctrl.y.comment,2) + "'"       + $
                     ',XTICKS    =' + STRING(ctrl.x.nb_tick)                      + $
                     ',XMINOR    =' + STRING(ctrl.x.nb_minor)                     + $
                     ',YTICKS    =' + STRING(ctrl.y.nb_tick)                      + $
                     ',YMINOR    =' + STRING(ctrl.y.nb_minor)                     + $
                     ',/NODATA'                                                   + $
                     ',/DEVICE'                                                   + $
                     ',/NOERASE'
           ret = EXECUTE (cmd_str) 

           ; Contour 
           ; -------
           IF (ctrl.contour_flg NE 0 AND lp_cnt_flg EQ 1) THEN BEGIN
             CONTOUR, data                                       , $
                      XSTYLE    = 5                              , $
                      YSTYLE    = 5                              , $
                      NLEVELS   = ctrl.contour_flg               , $
                      /NOERASE 
             ret = EXECUTE (cmd_str)  ; Restore axis
           ENDIF

           ; line identification marks
           ; -------------------------
           i=0
           WHILE (curr_banner_i.mark_line(i).lambda NE 0.0) DO BEGIN
             ydev=curr_banner_i.mark_line(i).lbl_y
             string= STRTRIM(curr_banner_i.mark_line(i).line_name,2)

             xx1 = curr_banner_i.mark_line(i).lambda    
             xx0 = xx1 - 0.0035 * (curr_dctrl_i.x.plot_max-curr_dctrl_i.x.plot_min)
             xx2 = xx1 + 0.0035 * (curr_dctrl_i.x.plot_max-curr_dctrl_i.x.plot_min)

             yy0 = curr_dctrl_i.y.plot_max+0.03 * (curr_dctrl_i.y.plot_max-curr_dctrl_i.y.plot_min)
             yy1 = curr_dctrl_i.y.plot_max+0.02 * (curr_dctrl_i.y.plot_max-curr_dctrl_i.y.plot_min)
             yy3 = curr_dctrl_i.y.plot_min + $
                 (FLOAT(ydev-FLOAT(curr_dctrl_i.y.offset))/FLOAT(curr_dctrl_i.y.plot_sz))* $
                  (curr_dctrl_i.y.plot_max-curr_dctrl_i.y.plot_min)
             yy2 = yy3 + 0.02 * (curr_dctrl_i.y.plot_max-curr_dctrl_i.y.plot_min)

             XA=[xx1, xx1, xx0, xx1, xx2, xx1]
             YA=[yy1, yy2, yy2, yy3, yy2, yy2]
   
             PLOTS,XA(0:1),YA(0:1), /DATA
             POLYFILL,XA,YA, /DATA
             XYOUTS,xx1, yy0, string, ALIGNMENT=0.5, /DATA
             i  = i+1
           ENDWHILE

           ; Color Scale 
           ; -----------
           IF (lp_dat_flg EQ 1) THEN BEGIN
             tab = BINDGEN (1,!D.N_COLORS)
               tab = BYTSCL(tab                                    , $
                            MIN = color_min                        , $
                            MAX = (color_max*(!D.N_COLORS-1))/199.0, $
                            TOP =!D.N_COLORS-1)
             TV, tab                                       , $
                 (PG_XL_MARGIN + szx + PG_XR_MARGIN )/10.0 , $
                 PG_YB_MARGIN/10.0                         , $
                 XSIZE = 3.0/10.0                          , $
                 YSIZE = szy/10.0                          , $
                 /CENTIMETERS       

             XSCL =  !D.X_PX_CM * $
                     [(PG_XL_MARGIN + szx + PG_XR_MARGIN )/10.0     , $
                     (PG_XL_MARGIN  + szx + PG_XR_MARGIN + 3 )/10.0 , $
                     (PG_XL_MARGIN  + szx + PG_XR_MARGIN + 3 )/10.0 , $
                     (PG_XL_MARGIN  + szx + PG_XR_MARGIN )/10.0     , $
                     (PG_XL_MARGIN  + szx + PG_XR_MARGIN )/10.0]
             YSCL =  !D.Y_PX_CM * $
                     [PG_YB_MARGIN/10.0                             , $
                     PG_YB_MARGIN/10.0                              , $
                     (PG_YB_MARGIN+szy)/10.0                        , $
                     (PG_YB_MARGIN+szy)/10.0                        , $
                     PG_YB_MARGIN/10.0]

             PLOTS, XSCL, YSCL, /DEVICE

             XYOUTS                                                        , $
                 (PG_XL_MARGIN + szx + PG_XR_MARGIN + 4.0)*!D.X_PX_CM/10.0 , $
                 (PG_YB_MARGIN + (szy*color_min/199.0)) * !D.Y_PX_CM/10.0  , $
                 STRTRIM(STRING(color_min), 2)                             , $
                /DEVICE
             XYOUTS                                                        , $
                 (PG_XL_MARGIN + szx + PG_XR_MARGIN + 4.0)*!D.X_PX_CM/10.0 , $
                 (PG_YB_MARGIN + (szy*color_max/199.0)) * !D.Y_PX_CM/10.0  , $
                 STRTRIM(STRING(FIX((color_max*(!D.N_COLORS-1))/199.0)),2) , $
                 /DEVICE
           ENDIF

           ; Stat Values 
           ; -----------
           x = (PG_XL_MARGIN              ) * !D.X_PX_CM/10.0
           y = (PG_YB_MARGIN + szy + 14.0  ) * !D.Y_PX_CM/10.0
           XYOUTS, x, y,STRMID(i_ban_p_fix_str,0, 70), /DEVICE

           x = (PG_XL_MARGIN              ) * !D.X_PX_CM/10.0
           y = (PG_YB_MARGIN + szy + 11.0  ) * !D.Y_PX_CM/10.0
           XYOUTS, x, y,STRMID (i_ban_d_fix_str, 0, 70), /DEVICE                

           ; Header Info and Title
           ; ---------------------
           X    =  !D.X_PX_CM * $
                   [(PG_XL_MARGIN        )/10.0  , $
                    (PG_XL_MARGIN  + 170.0)/10.0 , $
                    (PG_XL_MARGIN  + 170.0)/10.0 , $
                    (PG_XL_MARGIN         )/10.0 , $
                    (PG_XL_MARGIN         )/10.0]
           Y    =  !D.Y_PX_CM * $
                   [(PG_YB_MARGIN+szy+24.0)/10.0 , $
                    (PG_YB_MARGIN+szy+24.0)/10.0 , $
                    (PG_YB_MARGIN+szy+65.0)/10.0 , $
                    (PG_YB_MARGIN+szy+65.0)/10.0 , $
                    (PG_YB_MARGIN+szy+24.0)/10.0]
           PLOTS, X, Y, /DEVICE

           Y    =  !D.Y_PX_CM * $
                   [(PG_YB_MARGIN+szy+65.0)/10.0 , $
                    (PG_YB_MARGIN+szy+65.0)/10.0 , $
                    (PG_YB_MARGIN+szy+70.0)/10.0 , $
                    (PG_YB_MARGIN+szy+70.0)/10.0 , $
                    (PG_YB_MARGIN+szy+65.0)/10.0]
           PLOTS, X, Y, /DEVICE


           x = (PG_XL_MARGIN+57.0)*!D.X_PX_CM/10.0 
           y = (PG_YB_MARGIN + szy + 67.0) * !D.Y_PX_CM/10.0  
           XYOUTS, x, y,STRTRIM(ctrl.title,2), /DEVICE

           ql_format_hd, curr_header_i, text_value, err
           FOR i=0, 10 DO BEGIN
             x = (PG_XL_MARGIN + 2.0)*!D.X_PX_CM/10.0 
             y = (PG_YB_MARGIN + szy + 60.0 - i*3.0) * !D.Y_PX_CM/10.0  
             XYOUTS, x, y, text_value(i), /DEVICE
           ENDFOR

           j=0
           FOR i=11,N_ELEMENTS(text_value)-1 DO BEGIN
             x = (PG_XL_MARGIN+80.0)*!D.X_PX_CM/10.0 
             y = (PG_YB_MARGIN + szy + 60.0 - j*3.0) * !D.Y_PX_CM/10.0  
             XYOUTS, x, y, text_value(i), /DEVICE
             j = j+1
           ENDFOR
         END
    
     ELSE: err = 1
  ENDCASE  
  
  ; Update Banner 
  ; -------------
  ql_update_banner, mode, err

END
