pro plot_trav, p_st_day, p_en_day, trav_arr=trav_arr, nozoom=nozoom, noplot_n=noplot_n, $
	sxt=sxt, bcs=bcs, lparl_ops=lparl_ops, infil=infil, dates=dates, qdebug=qdebug, $
	ops=ops, noclear=noclear, apartments=apartments, only_lparl=only_lparl, $
	nomark=nomark, qstop=qstop, $
	invert=invert, charsize=charsize
;
;+
;NAME:
;	plot_trav
;PURPOSE:
;	To plot the travel plans for the SXT team at ISAS.  User has 
;	ability to interactively expand the plot over a given time period.
;CALLING SEQUENCE:
;	plot_trav		;plot all sxt people, full time range
;	plot_trav, /sxt		;plot all sxt people, full time range
;	plot_trav, /bcs		;plot all bcs people, full time range
;	plot_trav, '1-jan-91', '1-jan-92'	;all people for 1991
;	plot_trav, /lparl_ops
;	plot_trav, /noplot_n
;	plot_trav, infil='travel_loren.txt'
;	plot_trav, /dates
;OPTIONAL INPUT:
;	p_st_day- The starting day to plot.  If undefined, plot
;		  from first day of data.
;	p_en_day- The ending day to plot. If undefined, plot to
;		  last day of data.
;OPTIONAL KEYWORD INPUT:
;	trav_arr- The structure which holds the travel information.
;		  If undefined, read the data
;	lparl_ops- If set, only plot the key LPARL operations 
;		  personnel.
;	nozoom	- If set, do not allow interactive zooming 
;	noplot_n- If set, do not plot a summary of the number of
;		  personnel present at ISAS.
;	sxt	- If set, use the SXT team file
;	bcs	- If set, use the BCS team file
;	infil	- Read the travel information from this file
;	dates	- If set, print the starting and ending date of the travel
;		  on the plots
;	ops	- If set, plot the OPS people (LPARL plus Co-I)
;	noclear - If set, do not call CLEAR_UTPLOT at the end of the routine
;	apartments- If set, print the assigned apartment number.
;	only_lparl - If set, only list LPARL or LTSC people
;	nomark	- If set, don't mark the current time
;       invert   - If set, black on white (default for PS)
;       charsize - character size (default=1) (scaled by existing hard-coded #)
;
;HISTORY:
;	Written 29-Apr-92 by M.Morrison
;	22-Sep-92 (MDM) - Added /SXT and /BCS
;			- Added /YEAR switch to UTPLOT call
;	22-Feb-93 (MDM) - Added Bruner to /LPARL list
;	 4-Mar-93 (MDM) - Added INFIL option
;	17-Mar-93 (MDM) - Added DATES option
;	 1-Apr-93 (MDM) - Added /OPS option
;	12-Apr-93 (MDM) - Implemented the /NOPLOT_N option
;			- Added /NOCLEAR option
;	 4-May-93 (MDM) - Modified DATES option to print the proper ending date
;			  of the travel.  It was off by one.
;	22-Sep-93 (MDM) - Minor mod (tit=' ' for # people at isas plot)
;	 2-Nov-93 (RDB) - Small correction of name alignment on y-axis; got rid of "0" at top
;	 8-Nov-93 (MDM) - Added Handey and Alexander to OPS and LPARL listing
;	 7-Feb-94 (MDM) - Changed calls to UTPLOT because of changes to UTPLOT
;	 2-Jun-94 (GAL)	- Changed hardcopy calls to pprint from lprint.
;	 8-Jun-94 (GAL) - Added apartments option and reorganized database.
;	 3-Aug-94 (MDM) - Added /ONLY_LPARL option
;        3-Aug-94 (GAL) - Added Weber to OPS and LPARL listings
;	 8-Aug-94 (MDM) - Changed plot command to not use ytickname and to draw the
;			  labels myself (since there are over 31)
;	 3-Nov-94 (JRL) - Fixed tick label software. Added nomark keyword. Fixed overplotting
;			  of y-axis by the year boundary markers.
;       20-Feb-95 (JRL) - Added Shing to OPS and LPARL listings
;	28-Sep-95 (GAL) - Added Serge to OPS and LPARL listings
;	 2-Apr-96 (GAL) - Moved Jean-Pierre to LM group.
;	 5-Apr-96 (GAL) - Moved Tom Metcalf to LM group.
;       28-Jun-96 (NN)  - Inserted /update in rd_travel which is used for plot
;       10-jul-96 (SLF) - add INVERT, keyword and function
; 	30-Sep-96 (NN)  - Eliminated Handy and Moved Alexander to Lockheed
;-
;
; slf - allow charsize and auto-scale down if Z buffer.
invert=keyword_set(invert) or strupcase(!d.name) eq 'PS'
if n_elements(charsize) eq 0 then charsize=([1,.7])(strupcase(!d.name) eq 'Z')

if (n_elements(trav_arr) eq 0) then trav_arr=rd_travel(sxt=sxt, bcs=bcs, infil=infil, update=update)
;
st_day = min(trav_arr.day)
en_day = max(trav_arr.day + trav_arr.ndays)
ref_day = fmt_tim(anytim2ex([0,st_day]))
ndays = float(en_day-st_day + 1)
names 		= strmid(trav_arr.name+'                    ', 0, 11)
institute	= strmid(trav_arr.institute+'                        ', 0, 20)
sort_arr 	= institute + names
;
qzoom = not keyword_set(nozoom)		;nice double negative
qplot_n = not keyword_set(noplot_n)
if (keyword_set(lparl_ops)) then begin
    group = strarr(n_elements(trav_arr))
    trav_assign_grp, trav_arr, group, 'lemen', 'A. Scientist'
    trav_assign_grp, trav_arr, group, 'metcalf', 'A. Scientist'
    trav_assign_grp, trav_arr, group, 'nitta', 'A. Scientist'
    trav_assign_grp, trav_arr, group, 'savy', 'A. Scientist'
    trav_assign_grp, trav_arr, group, 'wuelser', 'A. Scientist'
    trav_assign_grp, trav_arr, group, 'linford', 'B. Engineer'
    trav_assign_grp, trav_arr, group, 'freeland', 'B. Engineer'
    trav_assign_grp, trav_arr, group, 'slater', 'B. Engineer'
    trav_assign_grp, trav_arr, group, 'acton', 'C. Scientist'
    trav_assign_grp, trav_arr, group, 'alexander', 'A. Scientist'
    trav_assign_grp, trav_arr, group, 'canfield', 'C. Scientist'
;    trav_assign_grp, trav_arr, group, 'handy', 'C. Scientist'
    trav_assign_grp, trav_arr, group, 'weber', 'C. Scientist'
    trav_assign_grp, trav_arr, group, 'mckenzie', 'C. Scientist'
    trav_assign_grp, trav_arr, group, 'hudson', 'D. Scientist'
    group = strmid(group+'                        ', 0, 20)
    sort_arr 	= group + names
end
;	removed from lparl_ops
;    trav_assign_grp, trav_arr, group, 'strong', 'A. Scientist'
;    trav_assign_grp, trav_arr, group, 'morrison', 'B. Engineer'
;    trav_assign_grp, trav_arr, group, 'martens', 'A. Scientist'
;    trav_assign_grp, trav_arr, group, 'bruner', 'A. Scientist'
;    trav_assign_grp, trav_arr, group, 'shing', 'B. Engineer'
;
if (keyword_set(only_lparl)) then begin
    group = strarr(n_elements(trav_arr))
    trav_assign_grp, trav_arr, group, 'lemen', 'A. Scientist'
    trav_assign_grp, trav_arr, group, 'metcalf', 'A. Scientist'
    trav_assign_grp, trav_arr, group, 'nitta', 'A. Scientist'
    trav_assign_grp, trav_arr, group, 'savy', 'A. Scientist'
    trav_assign_grp, trav_arr, group, 'wuelser', 'A. Scientist'
    trav_assign_grp, trav_arr, group, 'linford', 'B. Engineer'
    trav_assign_grp, trav_arr, group, 'freeland', 'B. Engineer'
    trav_assign_grp, trav_arr, group, 'slater', 'B. Engineer'
    trav_assign_grp, trav_arr, group, 'shing', 'B. Engineer'
    group = strmid(group+'                        ', 0, 20)
    sort_arr 	= group + names
end
;
;	removed from only_lparl
;    trav_assign_grp, trav_arr, group, 'strong', 'A. Scientist'
;    trav_assign_grp, trav_arr, group, 'bruner', 'A. Scientist'
;
if (keyword_set(ops)) then begin
    group = strarr(n_elements(trav_arr))

    trav_assign_grp, trav_arr, group, 'bruner', 'A. Scientist'
    trav_assign_grp, trav_arr, group, 'lemen', 'A. Scientist'
    trav_assign_grp, trav_arr, group, 'nitta', 'A. Scientist'
    trav_assign_grp, trav_arr, group, 'savy', 'A. Scientist'
    trav_assign_grp, trav_arr, group, 'strong', 'A. Scientist'
    trav_assign_grp, trav_arr, group, 'wuelser', 'A. Scientist'
    trav_assign_grp, trav_arr, group, 'metcalf', 'A. Scientist'
    trav_assign_grp, trav_arr, group, 'linford', 'B. Engineer'
    trav_assign_grp, trav_arr, group, 'freeland', 'B. Engineer'
    trav_assign_grp, trav_arr, group, 'slater', 'B. Engineer'
    trav_assign_grp, trav_arr, group, 'shing', 'B. Engineer'
    trav_assign_grp, trav_arr, group, 'acton', 'C. Scientist'
    trav_assign_grp, trav_arr, group, 'alexander', 'C. Scientist'
    trav_assign_grp, trav_arr, group, 'canfield', 'C. Scientist'
    trav_assign_grp, trav_arr, group, 'handy', 'C. Scientist'
    trav_assign_grp, trav_arr, group, 'weber', 'C. Scientist'
    trav_assign_grp, trav_arr, group, 'mckenzie', 'C. Scientist'
    trav_assign_grp, trav_arr, group, 'hudson', 'D. Scientist'
    trav_assign_grp, trav_arr, group, 'labonte', 'E. Co-I Scientist'
    trav_assign_grp, trav_arr, group, 'leka', 'E. Co-I Scientist'
    trav_assign_grp, trav_arr, group, 'mctiernan', 'E. Co-I Scientist'
    trav_assign_grp, trav_arr, group, 'klimchuk', 'E. Co-I Scientist'
    group = strmid(group+'                        ', 0, 20)
    sort_arr 	= group + names
end
;	removed from ops
;    trav_assign_grp, trav_arr, group, 'martens', 'A. Scientist'
;    trav_assign_grp, trav_arr, group, 'morrison', 'B. Engineer'

sort_list 	= sort_arr( uniq(sort_arr, sort(sort_arr)))
ss = where(strmid(sort_list,0,5) ne '     ')
sort_list = sort_list(ss)			;get rid of items that have no secondary key
nlist 	= n_elements(sort_list)
yticknam      = [' ', strtrim(strmid(sort_list, 20, 11),2)+' ', ' ',' ',' ']          ;*** RDB
xrange0 = [0, ndays*86400]
xrange = xrange0
;
if (n_elements(p_st_day) ne 0) then xrange(0) = int2secarr(anytim2ex(p_st_day), ref_day)
if (n_elements(p_en_day) ne 0) then xrange(1) = int2secarr(anytim2ex(p_en_day), ref_day)
timerange = anytim2ints(ref_day, off=[0, ndays*86400])
;
x_days = replicate({pl_trav_summ, day: fix(0), time: long(0)}, ndays)
x_days.day = indgen(ndays) + st_day
;
if (!d.name eq 'PS') then device, /land
;
qdone = 0
qhard = 0
while (not qdone) do begin
    if (qplot_n) then !p.region = [0,.2,0.95,.95] else !p.region = 0
    y_days = intarr(ndays)	;zero each time around

    ;;utplot, [0, ndays*86400], [0,0], ref_day, /nodata, $
    ;;		xrange=xrange, xmargin=[11,3], xstyle=1, $
    ;;		yrange=[nlist+1,0], yticks=nlist+2, yticknam=yticknam, ytickv=indgen(nlist+2), /year
    ;;utplot, timerange, [0,0], ref_day, /nodata, $
    ;;		xrange=xrange, xmargin=[11,3], xstyle=1, $
    ;;		yrange=[nlist+1,0], yticks=nlist+2, yticknam=yticknam, ytickv=indgen(nlist+2), /year
    color=([255,0])(invert)
    utplot, timerange, [0,0], ref_day, /nodata, $
		xrange=xrange, xmargin=[11,3], xstyle=1, $
		yrange=[nlist+1,0], yticks=1, yticknam=strarr(2)+' ', /year, ystyle=1,  $
                title='ISAS travel    updated '+update, color=color, back=(255-color)
    x0 = convert_coord(0.01, 0, /normal, /to_data)
    x1 = (!x.crange(1)-!x.crange(0))*0.015
    offs = ((.5-.05)/(20-6.)*nlist - .143) < .5 > .05		; empirically derived- improves alignment
								; for small number of names
    for i=0,nlist+1 do begin
	xyouts, x0(0), i+offs, yticknam(i), /data,charsize=charsize, $
	   color=([255,0])(invert)
	oplot, [!x.crange(0), !x.crange(0)+x1], [1,1]*i, $	;make tick
	   color=([255,0])(invert)
	oplot, [!x.crange(1)-x1, !x.crange(1)], [1,1]*i, $	;make tick
	   color=([255,0])(invert)
    end
    if (keyword_set(qstop)) then stop

; Indicate year boundaries
    for iyr=92,95 do begin
	xx = int2secarr(anytim2ex('1-jan-'+strtrim(iyr,2)), ref_day) + [0,0]
	yy = !y.crange
	color=50
        color=([50,255-color])(invert)        
	if min(abs((xx-xrange)/(xrange(1)-xrange(0)))) gt .1 then $	; Don't overplot y-axis
		oplot, xx, yy, color=color
    end

    for i=0,nlist-1 do begin
	off = i+1
	ss = where(sort_arr eq sort_list(i))
	for j=0,n_elements(ss)-1 do begin
	    trav0 = trav_arr(ss(j))
	    xx = int2secarr(trav0, ref_day) + [0,trav0.ndays*86400]
	    yy = off(0)*[1,1]
	    case trav0.code of
		    0: begin & linestyle=1 & linethick=1 & color=255 & end
		    1: begin & linestyle=0 & linethick=1 & color= 10 & end
		    2: begin & linestyle=0 & linethick=4 & color=255 & end
		    3: begin & linestyle=0 & linethick=2 & color= 50 & end
	    endcase
            color=([color,255-color])(invert)        
	    oplot, xx, yy, linestyle=linestyle, thick=linethick, color=color
	    ;if (keyword_set(dates)) then begin
	    if ((keyword_set(dates)) and (trav0.code eq 2)) then begin
		dx = !x.crange(1) - !x.crange(0)
		dy = !y.crange(1) - !y.crange(0)
		tarr = anytim2ex(trav0)
		if ((xx(0) ge !x.crange(0)) and (xx(0) le !x.crange(1))) then $
						xyouts, xx(0),        yy(0)+dy*.01, strtrim(tarr(4),2), charsize=0.75*charsize,   color=([255,0])(invert)

		tarr = anytim2ex(anytim2ints(trav0, off=(trav0.ndays-1)*86400.))
		if ((xx(1) ge !x.crange(0)) and (xx(1) le !x.crange(1))) then $
						xyouts, xx(1)-dx*.02, yy(0)+dy*.01, strtrim(tarr(4),2), charsize=0.75*charsize, color=([255,0])(invert)



	    end

	    if ((strtrim(trav0.apartment,2) ne '') AND (keyword_set(apartments)) AND (trav0.code eq 2) ) then begin
		dx = !x.crange(1) - !x.crange(0)
		dy = !y.crange(1) - !y.crange(0)	    
		aptx = ( (xx(1)-dx*.02) - xx(0) )/2. + xx(0)			
		if ((xx(0) ge !x.crange(0)) and (xx(1) le !x.crange(1))) then $
						xyouts, aptx, yy(0)+dy*.01, 'A'+strtrim(trav0.apartment,2), charsize=0.75*charsize, color=([255,0])(invert)

	    endif

	    if (trav0.code eq 2) then begin
		ii = trav0.day-st_day
		for k=0,trav0.ndays-1 do y_days(ii+k) = y_days(ii+k) + 1
	    end
	end

	if (i gt 0) then if (strmid(sort_list(i),0,20) ne strmid(sort_list(i-1),0,20)) then begin
	    xx = !x.crange
	    yy = off-0.5 + [0,0]
	    oplot, xx, yy, linestyle=2, color=([255,0])(invert)

	end
    end

; ----------------------
; Mark the current time
    xx = int2secarr(anytim2ex(!stime), ref_day) + [0,0]
    yy = !y.crange
    if not keyword_set(nomark) then oplot, xx, yy, linestyle=2, color=([255,0])(invert)


    if (qplot_n) then begin
	!p.region = [0,.05,.95,.2]
	x = int2secarr(x_days, ref_day)
	ss = where((x ge xrange(0)) and (x le xrange(1)))
	yrange = [0, max(y_days(ss))+1]
	utplot, x_days, y_days, ref_day, xtitle=' ', psym=10, /noerase, $
				xrange=xrange, xmargin=[11,3], xstyle=1, $
				yrange=yrange, ymargin = [0,0], ytitle = '# People at ISAS', /year, tit=' ', $
			        color=color, background=(255-color)
    end

    plottime, 0, 0, 'PLOT_TRAV.PRO  Ver 1.1  10-Jul-96
    plottime
    if (keyword_set(qdebug)) then stop

    qdone = 1
    qavoid = ((!d.name eq 'PS') and (not qhard))	;user set device to 'PS' outside of routine
    if (qzoom and (not qavoid)) then begin
	if (qhard) then begin
	    pprint
	    set_plot, save_dev
	    qhard = 0
	end

	ss=plot_lcur(x_days, y_days, ref_day, /noplot, qblowup=qblowup, qhard=qhard, qreset=qreset)
	qdone = (not qhard and not qblowup and not qreset)
	if (qblowup) then xrange=int2secarr(x_days([ss(0), ss(n_elements(ss)-1)]), ref_day)
	if (qreset) then xrange = xrange0
	if (qhard) then begin
	    save_dev = !d.name
	    set_plot,'ps
	    device, /land
	end
    end
end
;
if (not keyword_set(noclear)) then clear_utplot
!p.region = 0
end

