subr t3d_view(i)
 ;the view routine, check if a file open and get current image #
 if $t3d_file_open_flag ne 1 then {
  ;try to read the current name and open the file
  if t3d_open_file() eq 0 then {
  	errormess,'no valid file to view'
	return
  }
 }
 x = get_trace_image(i)
 if isarray(x) eq 0 then {
   sq = sprintf('bad TRACE image\ncan''t decode\nimage %d in\n%s',i, $t3d_file_name)
   errormess,sq  return }
 ;for raw trace images, we orient them so that they have the normal solar
 ;directions, this depends on the amplifier
 xx = wmap($t3d_dp_header(*,i))
 if extract_bits(xx(102),12,1) eq 1 then {
  ;amp B case
  ;x = x(>1,>0)
  x = reorder(x,4)
 } else {
  ;amp A case
  ;x = reverse(x(>1,>0))		;should use a faster reorder
  x = reorder(x, 7)			;and we do but keep above for reference
 }
 
 nx = dimen(x, 0)		ny = dimen(x, 1)
 ;ty,' ready for view'
 ;which window ?
 labelq = trace_view_info(xx)	;getting the label also sets $trace_wave, etc
 if $t3d_routing_flag then {
  ;first by wavelength
  win = $t3d_route_win($t3d_routes($trace_wave))
  ;also check for little guys, they go into another place
  if $trace_nx le 256 and $trace_ny le 256 then win = $t3d_route_win(9)
 } else win = $current_window
 switch,x,eval('$data'+string(win))
 ;set some other window attached parameters
 $view_sun_pixel_scale(win) = $trace_pixel_size
 $view_sun_xc(win) = $trace_xc
 $view_sun_yc(win) = $trace_yc
 $view_tai(win) = $trace_tai
 ;11/23/98 - some selection parameters
 $view_data_type(win) = 1
 x = zero(fltarr(2))
 x(0) = $trace_et
 switch, x, eval('$view_trace_info_flt_'+string(win))
 x = zero(intarr(8))
 x(0) = $trace_nx  x(1) = $trace_ny  x(2) = $trace_wave
 x(3) = $trace_bm  x(4) = $trace_sai
 x(5) = $trace_ccdxbase  x(6) = $trace_ccdybase
 x(7) = $trace_sum
 switch, x, eval('$view_trace_info_int_'+string(win))
 
 x = 0

 ;do we want a despike ?
 if $viewdespikeflag(win) then viewdespike, win
 ;reduce emi ? this has the image already re-ordered
 if $viewemiflag(win) then viewemi, win

 if $view_scaletype(win) eq 5 then $view_scaletype(win) = 2
 view, win
 if $auto_size_flag then {
 ;try setting the zoom button according to nx size
 for zw=0,7 do xmtogglesetstate, $view_zoom_widgets(zw, win), 0, 0
 nxw = nx		nyw = ny	zmnew = 1   zw = 2
 if nx gt 768 then { zmnew = -2  nxw = nx/2  nyw = ny/2 }
 if nx lt 256 then { zmnew = 2	 nxw = nx*2  nyw = ny*2 }
 $view_zoom_fac(win) = zmnew
 if zmnew eq -2 then zw = 1 else if zmnew eq 2 then zw = 3
 xmtogglesetstate, $view_zoom_widgets(zw, win), 1, 0
 ;make the size about right and expose it, this makes the size fit
 xmsize, $view_draw(win), nxw, nyw
 xtloop,2
 view_expose_cb, win
 xtloop,2
 xmtogglesetstate, $view_zoom_widgets(zw, win), 1, 1
 }
 ;also put some basic info in the view next to the zoom buttons
 xmtextsetstring, $view_text_widget(win), labelq
 $view_text(win) = labelq
 endsubr
 ;======================================================= 
