Viewing contents of file '../idllib/contrib/tappin/graffer/gr_plot_object.pro'
pro Gr_plot_object, pdefs, no_null=no_null, charsize=charsize, $
                    plot_all=plot_all, grey_ps=grey_ps

;+
; GR_PLOT_OBJECT
;	Plots the plot specified by pdefs
;
; Usage:
;	gr_plot_object, pdefs	; Not intended to be used directly by
;				; the user
;
; Argument:
;	pdefs	struct	input	The structure containing the plot
;				definition
;
; Keyword:
;	no_null		input	If set, then don't plot null text
;				strings as "<NULL>"
;	charsize float	input	The character size to use as a
;				multiplier to the pdefs sizes (for
;				hardcopies)
;	plot_all	input	If set, then don't supress 2-D plots
;				even when this has been requested.
;	grey_ps		input	If set & non-zero, then the plot is to
;				a PS device without the COLOUR option.
;
; Side Effect:
;	A plot is generated on the current device.
;
; History:
;	Original: 2/8/95; SJT
;	Add text handling: 16/8/95; SJT
;	Add facilities for string-type data: 18/8/95; SJT
;	Move log axis locks here: 22/8/95; SJT
;	add charsize key: 4/9/95; SJT
;	Change GR_ERRPLOT calls to allow use of limits: 11/6/96; SJT
;	Add code to allow (a) addition of axes at the origin and (b)
;	Polar plots: 12/8/96; SJT
;	Use !{XY}.CRANGE for function limits: 29/8/96; SJT
;	Rename as GR_PLOT_OBJECT (was plot_object): 18/9/96; SJT
;	Add call to empty to force an update of the screen: 18/3/98; SJT
;-

if (pdefs.xtype and min(pdefs.xrange) le 0) then begin
    graff_msg, pdefs.ids.message, ['WARNING: zero or negative limit in ' + $
                                   'log plot', $ 
                                   '         not plotting']
    return    
endif

if (pdefs.ytype and min(pdefs.yrange) le 0) then begin
    graff_msg, pdefs.ids.message, ['WARNING: zero or negative limit in ' + $
                                   'log plot', $ 
                                   '         not plotting']
    return    
endif

xrange = pdefs.xrange
yrange = pdefs.yrange

if (xrange(0) eq xrange(1)) then begin
    graff_msg, pdefs.ids.message, ['WARNING: degenerate x-axis range', $
                                   '         not plotting']
    return    
endif
if (yrange(0) eq yrange(1)) then begin
    graff_msg, pdefs.ids.message, ['WARNING: degenerate y-axis range', $
                                   '         not plotting']
    return    
endif

if (not keyword_set(charsize)) then csiz = 1.0 $
else csiz = charsize

oposit = !P.position

gr_pl_axes, pdefs, csiz

xrange = !X.crange
if (pdefs.xtype) then xrange = 10^xrange
yrange = !Y.crange
if (pdefs.ytype) then yrange = 10^yrange

maxrange = sqrt(max(xrange^2)+max(yrange^2))

handle_value, pdefs.data, data, /no_copy

cts = data.psym eq 0
ndata = data.ndata
type = data.type

handle_value, pdefs.data, data, /no_copy, /set

plot2 = keyword_set(plot_all) or (not pdefs.opts.s2d)

for i = 0, pdefs.nsets-1 do begin
                                ; N.B. Do not use /no_copy
                                ; here because we may need to sort the
                                ; data and we don't want to change to
                                ; order in the storage array.
    
    
    if (ndata(i) ge 2 or (not cts(i) and ndata(i) eq 1)) then begin
        
        if (type(i) eq -4) then begin
            if (plot2) then $
              gr_2df_plot, pdefs, i, csiz, grey_ps=grey_ps ; 2 D function
        endif else if (type(i) lt 0) then begin
            gr_1df_plot, pdefs, i ; Function, data is struct
        endif else if (type(i) eq 9) then begin ; 2 D data
            if (plot2) then $
              gr_2dd_plot, pdefs, i, csiz, grey_ps=grey_ps
        endif else $                  ; Observations, xydata is
          gr_1dd_plot, pdefs, i ; floating point
    endif
endfor

if (pdefs.key.use) then gr_pl_key, pdefs, csiz ; Must follow
                                ; plotting the traces else grayscale
                                ; may obscure


;	Text strings

if (pdefs.ntext gt 0) then begin
    
    handle_value, pdefs.text, text, /no_copy

    opf = !P.font
    
    for j = 0, pdefs.ntext-1 do $
      gr_pl_text, text(j), csiz, no_null = keyword_set(no_null)
    
    !P.font = opf
                
    if (not keyword_set(no_null)) then begin ; Plot text anchors
        usersym, [-.5, 0., 0., 0., .5], [-.866, 0., -1.77, 0., -.866]
        lf = where(text.norm eq 2, nf)
        if (nf ne 0) then begin
            gr_fra2norm, text(lf).x, text(lf).y, xn, yn
            plots, /norm, psym = 8, xn, yn
        endif
        
        ln = where(text.norm eq 1, nn)
        if (nn ne 0) then plots, /norm, psym = 8, text(ln).x, $
          text(ln).y
        ld = where(text.norm eq 0, nd)
        if (nd ne 0) then plots, /data, psym = 8, text(ld).x, $
          text(ld).y
    endif
    
    
    handle_value, pdefs.text, text, /set, /no_copy
endif

empty                           ; Force an update

!P.position = oposit

pdefs.transient.opflag = 0b

end