\documentclass[11pt,psfig,preprint]{aastex}
\begin{document} 

\title{MAKING A COLORBAR/IMAGE COMBO \\ \today}

\author{Carl Heiles}

%\tableofcontents

	Here is a quick way to make a colorbar/image combination. 
Colorbars are important: the colorbar is like labeling your intensity
axis.  This is just as important as labeling your other axes!

	You {\it must use our local versions} of \verb$colorbar$ and
\verb$display$, which (for ugastro) are locataed in
\verb$~ay121/idl/gen$.  To check this: the local \verb$display$ has no
documentation whatsoever; and for \verb$colorbar$, When you type
\verb$doc_library, colorbar$ in IDL, one of the top few lines says

\verb$ **** WORK IN PROGRESS;; DOCUMENTATION MAY WELL BE WRONG!!!!!!!!$

\noindent But it really does work!

	Our attached figures provide two examples of colorbar-calibrated
images, one with a vertical and one a horizontal colorbar.  Getting
these positioned and sized is a bit tricky and you can do it
yourself---or you can use our routine \verb$cb_setup$. You
invoke it with

\verb$cb_setup, xim, yim, posplot, posbar, w, cbx, sep, vertical=vertical$

\noindent If you like the default setup on our figures, you don't need
to specify any inputs; alternatively, you can specify \verb$w, cbx, sep$
if you wish.  If you don't specify them they are outputs.  The
parameters are:

\begin{verbatim} 
OUTPUTS:
       xim is the horizontal size of image in normalized coordinates
       yim is the vertical size of image in normalized coordinates
       posplot[4] is the image position corners in normralized coordinates
       posbar[4] is the colorbar position corners in normalized coords

       w is the width of the frame (white blank space)
       cbx is the short dimension of the colorbar in normalized coordinates
       sep is the separation between the  colorbar and image in normalized coords
if w, cbx, and sep are not specified, their defaults are (0.1, 0.1, 0.04)
\end{verbatim}

	We now present the IDL commands required to make these
colorbar/image combinations.  We assume that: your image is size
\verb$xsz by ysz$ pixels; you want to display your image in greyscale;
the data values in your image range from 0 to 2 (corresponding to the
byte range of 0 to 255 in the image); and your image-axis and colorbar-axis
titles are as shown on the figures.  Also, setting \verb$ps$ gives you a
postscript output, not setting it gives you X-window output.  Use the
following IDL commands:

\clearpage

\begin{verbatim}
;IMG IS THE NAME OF THE IMAGE...
xsz= (size(img))[1]  ;NR OF X PIXELS IN IMAGE
ysz= (size(img))[2]  ;NR OF Y PIXELS IN IMAGE
vertical=1     ;GIVES VERTICAL COLORBAR
cb_setup, xim, yim, posplot, posbar, w, cbx, sep, vertical=vertical
        ;CALCULAATES THE LOCATION AND SIZE OF THE DISPLAY

if ps eq 1 then psopen, filename, /times, /bold, /isolatin1, /color ;OPENS PS FILE
if ps eq 0 then window, 9, xs= xsz/xim, ys= ysz/yim ;OPENS WINDOW
if ps eq 0 then device, decomposed=0 ;ASSURES YOU ARE USING A COLORTABLE
loadct, 0  ;*** ASSURES GREYSCALE
colr= [ [r_orig], [g_orig], [b_orig] ]  ;DEFINES COLR ARRAY USING GREYSCALE
tv, img, w, w, /norm, xsize=xim, ysize=yim ;WRITES THE IMAGE TO THE DISPLAY
setcolors, /system_variables; ASSURES YOUR COLORTABLES ARE OK FOR GRAPHICS
loadct,0 ;ASSURES BLACK/WHITE FOR LABELLING
plot, [0], [0], pos= posplot, $
            /xsty, /ysty, /norm, /noerase, /nodata, $
            xtit= 'X', ytit= 'Y', font=ps-1, back=!black
        ;ADDS PLOTTING AXES TO THE IMAGE
colorbar, pos= posbar, crange= [0.,2.], rgb=colr, $
            vertical= vertical, $
            xtitle= 'XT', ytitle= 'YT', font=ps-1;;; , xticks=4, yticks=4
        ;WRITE THE COLORBAR TO THE DISPLAY; USE XTICKS, YTICKS IF NEEDED
loadct,0 ;*** RESETS THINGS AFTER COLORBAR
if ps eq 1 then psclose ;CLOSES PS FILE
\end{verbatim}

If you want to use a different IDL colortable for the image and
colorbar, specify its number in the \verb$loadct$ statements annotated
with \verb$***$ above.  The above statements are also given in the
documentation of \verb$cb_setup$. 


\begin{figure}[h!]
\begin{center} \leavevmode
\includegraphics[scale=0.7]{cb_stst_v0.ps}
\end{center} \caption{Horizontal colorbar \label{horiz}}
\end{figure}                                                            
                    
\begin{figure}[h!]
\begin{center} \leavevmode
\includegraphics[scale=0.7]{cb_stst_v1.ps}
\end{center} \caption{Vertical colorbar \label{vertical}}
\end{figure}                                                            
                    
\end{document}
