pro fig_sum_img, f, x00, y00, img, tit, fmt=fmt, scl_min=scl_min0, scl_max=scl_max0
;
common fig_summary, nn, nxout, nyout, xmargin, ymargin
;
x0 = x00 + xmargin*nxout
y0 = y00 + ymargin*nyout
;
imin = min(img)
imax = max(img)
if (n_elements(scl_min0) eq 0) then scl_min = imin else scl_max=scl_max0
if (n_elements(scl_max0) eq 0) then scl_max = imax else scl_min=scl_min0
;
bimg = congrid(bytscl(img, scl_min, scl_max), nn, nn)
;
tv2, bimg,        x0, y0
mk_refbar,   x0+nn+5, y0, scl_min, scl_max, ysiz=nn, siz=f, fmt=fmt
xyouts2,     x0+nn/2, y0+nn+5, tit, align=0.5, /dev, siz=f*1.2
;
end
;------------------------------------------------------------------------------
pro fig_sum_plot, f, x00, y00, data, tit, code, fmt=fmt, xarr=xarr, $
		levels=levels, xcontour=xcontour0, ycontour=ycontour0, conrange=conrange
;
common fig_summary, nn, nxout, nyout, xmargin, ymargin
;
x0 = x00/nxout + xmargin
y0 = y00/nyout + ymargin
x1 = x0 + nn/nxout
y1 = y0 + nn/nyout
;
case code of
    'P': plot, xarr, data, /noerase, position = [x0, y0, x1, y1], tit=tit, psym=10, /ynozero, /xstyle
    'C': begin
		nx = n_elements(data(*,0))
		ny = n_elements(data(0,*))
		if (n_elements(xcontour0) eq 0) then xcontour=findgen(nx) else xcontour=xcontour0
		if (n_elements(ycontour0) eq 0) then ycontour=findgen(ny) else ycontour=ycontour0
		if (n_elements(conrange) ne 0) then xcontour=(findgen(nx)/(nx-1)*2 - 1)*conrange(0)
		if (n_elements(conrange) ne 0) then ycontour=(findgen(ny)/(ny-1)*2 - 1)*conrange(1)
		contour, data, xcontour, ycontour, /noerase, position = [x0, y0, x1, y1], $
						tit=tit, /xstyle, /ystyle, /follow, levels=levels
	 end
    'V': begin
		xrange = data(0:1).x
		yrange = data(0:1).y
		str = strtrim(data.z,2)
		if (keyword_set(fmt)) then str = string(data.z, format=fmt)
		plot, data.x, data.y, /nodata, /noerase, position = [x0, y0, x1, y1], tit=tit, $
								xrange=xrange, yrange=yrange, /xstyle, /ystyle
		for i=2,n_elements(data)-1 do xyouts, data(i).x, data(i).y, str(i), align=0.5, siz=0.7
	 end
    else:
end
;
end
;------------------------------------------------------------------------------
pro fig_summary, tit, codes, data1, dtit1, data2, dtit2, data3, dtit3, data4, dtit4, $
		con1range=con1range, con2range=con2range, con3range=con3range, con4range=con4range, $
		comments=comments, progver=progver2, hc=hc, $
		scl_min=scl_min, scl_max=scl_max, fmt=fmt, $
		subtit=subtit, $
		levels=levels, xcontour=xcontour, ycontour=ycontour, $
		xshift=xshift, $
		xarr=xarr, $
		qstop=qstop
;+
;NAME:
;	fig_summary
;PURPOSE:
;	To display image, contour, plots or values information on a figure.
;INPUT:
;OPTIONAL INPUT:
;OPTIONAL KEYWORD INPUT:
;	xshift	- Shift plots by normalized amount
;		  xshift = [0, .05]	;move right plots over 5%
;HISTORY:
;	Written 27-Jun-94 by M.Morrison
;V1.1	 6-Sep-94 (MDM) - Added XSHIFT option
;V1.2	12-Sep-94 (MDM) - Allowed SCL_MIN and SCL_MAX to be arrays
;-
;
common fig_summary, nn, nxout, nyout, xmargin, ymargin
;
progver = 'FIG_SUMMARY Ver 1.20 '
if (keyword_set(progver2)) then progver = progver2 + ' / ' + progver
;
if (keyword_set(hc)) then begin
    f = 0.8
    save_charsize = !p.charsize
    save_device = !d.name
    save_color = !color
    set_plot, 'ps
    !color = 0
    !p.charsize = f
end else begin
    f = 6.0 / font_size(1)
    !p.charsize = f
end
;
nn = 200
nxout = 2.0*nn*1.5
nyout = 2.5*nn*1.5
xmargin = 0.07		;margin around plot and contours in normalized units
ymargin = 0.04

tv2, nxout, nyout, /init, win=1, /already
erase
;
;---------------------------------------- Text information
;
ntit = n_elements(tit)
nstit = n_elements(subtit)
for i=1,ntit  do xyouts2, nxout/2, nyout-25*i, tit(i-1), align=0.5, siz=f*2.2, /dev
for i=1,nstit do xyouts2, nxout/2, nyout-15*i-25*ntit, subtit(i-1), align=0.5, siz=f*1.6, /dev
xyouts2, 0, 0, progver, /dev, siz=f
xyouts2, nxout/2, 0, 'Program Run: ' + !stime, /dev, siz=f
;
xx = nxout*0.05
yy = nyout - ntit*25 - nstit*15 - 50
;
step = 15
for i=0,n_elements(comments)-1 do xyouts2, xx, yy-i*step, comments(i), /dev, siz=f
;
;---------------------------------------- Displays
dxwin = nn/nxout
dywin = dxwin
dxskip = 1/3.
dyskip = 1/6.
for i=0,n_elements(codes)-1 do begin
    x0 = (i mod 2)   * nxout/2.
    y0 = (1 - (i/2)) * nxout/2.
    if (keyword_set(xshift)) then x0 = x0 + xshift(i mod 2) * nxout
    ;
    si = strtrim(i+1,2)
    cmd = 'f, x0, y0, data' + si + ', dtit' + si
    if (n_elements(scl_min) ne 0) then scl_min0 = scl_min( i < (n_elements(scl_min)-1) )
    if (n_elements(scl_max) ne 0) then scl_max0 = scl_max( i < (n_elements(scl_max)-1) )
    case codes(i) of
	'I': cmd = 'fig_sum_img,  ' + cmd + ', fmt=fmt, scl_min=scl_min0, scl_max=scl_max0'
	'C': cmd = 'fig_sum_plot, ' + cmd + ', "C", fmt=fmt, levels=levels, xcontour=xcontour, ycontour=ycontour, conrange=con'+si+'range'
	'P': cmd = 'fig_sum_plot, ' + cmd + ', "P", fmt=fmt, xarr=xarr'
	'V': cmd = 'fig_sum_plot, ' + cmd + ', "V", fmt=fmt'
	'-':
	else: print, codes(i) + ' not recognized'
    end
    print, cmd
    stat = execute(cmd)
end
;
if (!d.name eq 'PS') then begin
    pprint
    !color = save_color
    set_plot, save_device
end
;
if (n_elements(save_charsize) ne 0) then !p.charsize = save_charsize
if (keyword_set(qstop)) then stop
end
