subr read_file, win
 ;2/12/2008 - use solarbdisplay routine for displaying Solar B SOT images
 ;1/7/2008 - add Solar B info for text box, assumes solarboptions called
 ;12/26/96 don't query about cubes, just load them
 ;11/11/96 remove nan's in fp arrays, may want to make this optional later
 ;usually called by a file selector, name must be in $selected_file
 ;displays an image file
 ;fty=file type = 0 for fz, = 1 for fits
 if xexist(win) eq 1 then xcursor, win, 150
 xflush
 ;open and display the file
 if defined(h) eq 0 then h=''	; or a problem with undefined argument
 if dataread(x, $selected_file, h) eq 1 then {
   ;check for Solar B (just SOT for now)
   if $instrument_type eq 3 then {
     $view_data_type(win) = 3 
     exchange, x, $sbdata
     exchange, h, $sbhead
     $current_window = win
     solarbdisplay, $selected_file, 0
   } else {
     $view_data_type(win) = 0	;or it may act like a previous type
     ;remove any nan's here for F*4 or F*8 data
     if symdtype(x) eq 3 or symdtype(x) eq 4 then zeronans, x
     if symdtype(x) eq 2 then zeronondata, x
     ;;ty,'array dim =', num_dim(x)
     ;symarr's will be 1-D and are caught below with any 3-D data
     nd = num_dim(x)
     if nd ne 2 then {
      ;some exception processing here, so far for cubes and 1-D plots
      ;also have to recognize some Solar B types
      if (nd eq 3 and symdtype(x) eq 0) or issymarr(x) then {
	switch, x, $data15
	;call a professional in toolset4 to finish the movie setup
	mvload_read, $selected_file
      } else if nd eq 1 then {
	;a 1-D array, just plot it in a pixmap and copy to view
	winplot, win, x
      } else {
	;check if it may have a mif type file
	if $multi_image_flag then {
	 iq = mif_open_file($selected_file)
	 } else if nd eq 3 then {
	 ;general 3-D arrays can sometimes be just presented
	 ;via the old "movie" viewer
	 framesetup_3d_fits, $selected_file
	 } else errormess, $mess5
      }
     } else {
      ;nd is 2 but if one of the dimensions is just 2, assume an x/y plot
      nx = dimen(x,0)  ny = dimen(x,1)
      if nx le 2 or ny le 2 then {
	winplot, win, x
      } else {
	;global updates only needed in 2-D image for the current window, don't
	;want to do this for movie files for example
	update_globals, win, x
      }
     }
   }
 } else {
  sq = '\nfile type unknown'
  if filesize($selected_file) lt 0 then sq = '\nfile doesn''t exist'
  errormess, $selected_file+sq
 }
 xcursor, win, 132
 endsubr
 ;=============================================================================
