
; Ed Esfandiari - December 1998
;
; NAME:
;
;   NEW_YSCALE
;
; PURPOSE:
;
;   new_yscale displays min and max y-range scale(s) for 1 to 9 plots and lets
;   the user change the values. The new values overwrite the input min and max 
;   values and are returned back to the caller if REPLOT option is used but the 
;   original values are returned if CANCEL option is used or number of plots
;   is outside of 1 to 9 range.
;
; CALLING SEQUENCE:
;
;   success = NEW_YSCALE(nplt,mn_ary,mx_ary,title_ary)
;
; INPUT/OUTPUT:
;
;   nplt      (I): number of plots for which yscale need to be modified (must be
;                  between 1 and 9).
;   mn_ary  (I/O): fltarr(nplt) containing min y-value for each plot.
;   mx_ary  (I/O): fltarr(nplt) containing max y-value for each plot.
;   title_ary (I): strarr(nplt) containing title for each plot.
;   success   (O): set to 0 (false) if CANCEL option is chosen or if nplt is 
;                  invalid. set to 1 (true) if REPLOT option is chosen.
;

Pro Get_Range_Event, event
 common yrange,mn,mx,success

 WIDGET_CONTROL, event.id, GET_UVALUE=uval
 WIDGET_CONTROL, event.top, GET_UVALUE=yscale   ; get structure from UVALUE

 case (uval) of
  'rdone': begin
            for i=0,yscale.nplt-1 do begin
              success= 1 
              widget_control,yscale.max_id(i),get_value=maxy
              widget_control,yscale.min_id(i),get_value=miny
              mx(i)=maxy
              mn(i)=miny
;              print,yscale.ptitle(i)+' min,max=' ,mn(i),mx(i)
            end
            WIDGET_CONTROL, /DESTROY, yscale.base
          end
  'can':  begin
            success= 0 
;            for i=0,yscale.nplt-1 do $
;              print,yscale.ptitle(i)+' min,max=' ,mn(i),mx(i)
            WIDGET_CONTROL, /DESTROY, yscale.base
          end
 endcase

END



Function new_yscale,nplt,mn_ary,mx_ary,title_ary
 common yrange,mn,mx,success

      success= 1 ; initialize to true 
      if(nplt lt 1 or nplt gt 9) then begin
        success= 0 ; set to false 
        msg=widget_message('Can only have between 1 to 9 plots.')
        return,success
      end

      mn= mn_ary
      mn= float(mn)
      mx= mx_ary
      mx= float(mx)
   
      rbase= widget_base(title="Rescale Y-axes", $
                        xoffset=10,/frame,/column)
      b=widget_base(rbase,/row,space=25)

      min_id= lonarr(nplt) & max_id= min_id 

      for i=0,nplt-1 do begin
        if(i eq 0 or i eq 3 or i eq 6) then $
           col= widget_base(b,/column,space=25) 
        row= widget_base(col,/column,frame=5)
        txt=widget_label(row,value=title_ary(i))
        max_id(i)=cw_field(row,/float,/column,title='Max',value=mx(i))
        min_id(i)=cw_field(row,/float,/column,title='Min',value=mn(i))
      end

      br= widget_base(rbase,/COL)
      brc1= widget_base(br,/ROW,space=50)
      done = WIDGET_BUTTON(brc1, VALUE='REPLOT', UVALUE='rdone',/FRAME)
      canc= WIDGET_BUTTON(brc1, VALUE='CANCEL', UVALUE='can',/FRAME)

      widget_control,/realize,rbase
      yscale={base: rbase,      $
              nplt: nplt,       $
              min_id: min_id,   $
              max_id: max_id,   $
              ptitle: title_ary $
      }
      widget_control,rbase, SET_UVALUE=yscale
      xmanager,'Get_Range',rbase,EVENT_HANDLER='Get_Range_Event',/MODAL

      mn_ary= mn
      mx_ary= mx
;      print,'mn_ary= ',mn_ary
;      print,'mx_ary= ',mx_ary
      return, success
END


