subr file_view, k
 ;set up a file selection dialog
 sk = string(k)
 wname = '$fv'+ sk
 if defined(eval(wname)) eq 1 then xtmanage, eval(wname) else {
 sq = 'enter path for file\nselection dialog\nor leave blank'
 sq = sq + '\nfor current directory'
 xmprompt, sq,'','prompt_cb', 1, $f7, '',!screen_width/2 -50,!screen_height/2-50
 xtloop, 1
 ;we get here after the prompt_cb lets us (it sets !motif = 0)
 dirq = $textfield_value
 xtloop, 0
 !motif = 1
 help_file = $help_path + '/instructions.fview'
 s1 = 'Viewer'+ sk
 scommand = 'display,'+ sk
 whs = wname + '_help'
 scancel = 'widget_dismiss, '+wname+','+whs
 shelp = 'widget_help, '+whs+ ','''+ help_file+''''
 iq=xmfileselect(0, s1, scommand,'Display', shelp, scancel,$f3,$f5, '', dirq)
 switch, iq, eval(wname)
 }
 return
 endsubr
 ;========================================================
