filename='filename'

set_plot,'ps';                       redirect output to postscript file
device,file=filename+'.eps';         specifically this file!
device,/color;                       plot can be in color
loadct,76,file='~weeks/ericcol.tbl'; load in my favorite color palette
pfontold=!P.FONT;                    save the old font
!P.FONT=1;                           switch to Postscript fonts
device,set_font='Times',/tt_font;    Times font, in particular

; these are just some colors Eric likes:
col6=21;  reddish purple
col5=42;  red
col4=160; green
col3=187; light blue/green
col2=216; dark blue
col1=255; dark purple

; sometimes when I have a figure with multiple stacked panels, I
; only want the x-axis to have numbers for the bottom panel.
; Therefore I use xtickname=bb to define all the names of the
; x-ticks to be blanks.  Thus the next two lines:
b=" "
bb=[b,b,b,b,b,b,b]

; ===============================BEGIN PLOTTING BELOW




; ===============================END PLOTTING ABOVE

!P.FONT=pfontold;           restore previous font
device,/close;              close the postscript file
set_plot,'X';               redirect plotting back to X-windows

; next two commands edit the postscript file so that the
; BoundingBox is exactly the size of the plot.  This is
; from http://www.inference.org.uk/mackay/perl/bbox_add.pl
; and then Eric wrote the second script.
spawn,'~weeks/bin/bbox_add.pl '+filename+'.eps'
spawn,'~weeks/bin/pagebbox.sh '+filename+'.eps'

; next few lines are to make a JPEG file in case you want to use
; it in powerpoint.  You can change -xsize=900 to change the
; resolution of the JPEG.  That is, larger numbers =
; more pixels.
spawn,'pstopnm -portrait -stdout -xsize=900 '+filename $
   +'.eps > blah.ppm'
spawn,'pnmtojpeg -quality=95 blah.ppm > '+filename+'.jpg'
spawn,'rm blah.ppm'
cropjpg,filename+'.jpg'
; cropjpg is a program Eric wrote that reads in a JPG file,
; crops the image to be the size of the graph, and then
; rewrites the revised JPG file

; load in the JPEG and display it, just for fun:
read_jpeg,filename+'.jpg',tmp

; this is to shrink the image, if needed
tmp1=small(reform(tmp(0,*,*)))
nx=n_elements(tmp1(*,0))
ny=n_elements(tmp1(0,*))
tmp4=bytarr(3,nx,ny)
tmp4(0,*,*)=tmp1
tmp4(1,*,*)=small(reform(tmp(1,*,*)))
tmp4(2,*,*)=small(reform(tmp(2,*,*)))
erase

; uncomment one of these!
tv,tmp,true=1    ; fullsize image
;tv,tmp4,true=1   ; halfsize image


