Viewing contents of file '../idllib/contrib/tappin/graffer/gr_2dd_plot.pro'
pro Gr_2dd_plot, pdefs, i, csiz, grey_ps=grey_ps

;+
; GR_2DD_PLOT
;	Plot a 2-D Data in graffer
;
; Usage:
;	gr_2dd_plot, pdefs, i
;
; Argument:
;	pdefs	struct	input	The Graffer control structure.
;	i	int	input	Which 
;	csiz	float	input	Charsize scaling (hardcopy only).
;
; Keyword:
;	grey_ps		input	If set & non-zero, then the plot is to
;				a PS device without the COLOUR option.
;
; History:
;	Original: 10/12/96; SJT
;	Made unique in 8.3: 11/2/97; SJT
;	Skip if inadequate colours: 8/5/97; SJT
;-

handle_value, pdefs.data, data, /no_copy
if (data(i).zopts.format eq 1 and $
    pdefs.short_colour and $
    not keyword_set(grey_ps)) then begin
    handle_value, pdefs.data, data, /no_copy, /set
    return
endif

handle_value, data(i).xydata, xydata, /no_copy

handle_value, xydata.z, z, /no_copy
handle_value, xydata.x, x, /no_copy
handle_value, xydata.y, y, /no_copy

if (data(i).zopts.format eq 0) then begin
    if (data(i).zopts.n_levels le 0) then begin
        if (data(i).zopts.n_levels eq 0) then nl = 6 $
        else nl = -data(i).zopts.n_levels
        locs = where(finite(z), nfin)
        if (nfin ne 0) then rg = (max(z(locs), min = mn)-mn) $
        else rg = 0.
        
        if (rg eq 0.) then begin
            graff_msg, pdefs.ids.message, 'Flat dataset - not able to ' + $
              'contour'
            goto, restore
        endif
        levels = rg * (findgen(nl)+.5)/nl + mn
    endif else $
      levels = data(i).zopts.levels(0:data(i).zopts.n_levels-1)
    
    if (data(i).zopts.label ne 0) then begin
        labels = (indgen(abs(data(i).zopts.n_levels)) - $
                  data(i).zopts.label/2) mod data(i).zopts.label eq 0
    endif else labels = 0
    
    contour, z, x, y, /overplot, /follow, $
      levels = levels,  $
      c_linestyle = data(i).zopts.style(0:data(i).zopts.n_sty-1 > 0), $
      c_colors =  data(i).zopts.colours(0:data(i).zopts.n_cols-1 > 0), $
      c_thick = data(i).zopts.thick(0:data(i).zopts.n_thick-1 > 0),  $
      fill = data(i).zopts.fill, c_labels = labels
    
endif else begin
    if (keyword_set(grey_ps)) then colour_range = [0, 255] $
    else colour_range = [16, 143 < !D.n_colors-1]
    gr_display_img, z, x, y, range = $
      data(i).zopts.range, colour_range = colour_range, $
      pixel_size = data(i).zopts.pxsize
    
    gr_pl_axes, pdefs, csiz, /overlay
endelse

Restore:

handle_value, xydata.z, z, /no_copy, /set
handle_value, xydata.x, x, /no_copy, /set
handle_value, xydata.y, y, /no_copy, /set

handle_value, data(i).xydata, xydata, /no_copy, /set
handle_value, pdefs.data, data, /no_copy, /set

end