;=============================================================================
; 
; this file is for being used with xop_ifc
;
; created: srio@esrf.fr 98-01-21
;
; Modified:
;          srio@esrf.fr 98-12-16 adapted to XOP2.0
;=============================================================================
;
;=============================================================================
; menu definitions
;=============================================================================
;
;
; This is the section that defines the menus in the main xop window.
; It may be customizable:
;    1) To add menus: use w(x) 20<x<100
;    2) to add calls: use wtmp=widget_...
;    3) To remove menus: comment the corresponding entry and ALL THE
;       SUBSEQUENT CALLS
;    4) To remove a call: just comment it
;    5) To change a call from one menu to a different one: just change
;       the widget identifies w(x) in the corresponding call.
<start>menu
w(1) = widget_button(w(0),VALUE='File',/MENU)
  wtmp0= widget_button(w(1),VALUE=state.ifc.title+' input parameters', /Menu)
  wtmp= widget_button(wtmp0,VALUE='Load from file...', UVALUE='FILEINPUT')
  wtmp= widget_button(wtmp0,VALUE='Save to file...', UVALUE='FILEINPUT')
  wtmp= widget_button(wtmp0,VALUE='Save as default', UVALUE='FILEINPUT')
  wtmp= widget_button(w(1),VALUE='Write files for xop/Optics', UVALUE='write_f_optics')
  wtmp= widget_button(w(1),VALUE='Quit', UVALUE='QUIT',/SEPARATOR)
w(2) = widget_button(w(0),VALUE='Set_Parameters', /MENU)
  wtmp= widget_button(w(2),VALUE='Set Parameters', UVALUE='SETPAR')
  wtmp= widget_button(w(2),VALUE='Set Defaults', UVALUE='SETDEF')
w(3) = widget_button(w(0),VALUE='Show',/MENU)
  wtmp= widget_button(w(3),VALUE='Plot Results',UVALUE='plot')
;  wtmp= widget_button(w(3),VALUE='View Results',UVALUE='view')
w(4) = widget_button(w(0),VALUE='Help', /Help)
  wtmp= widget_button(w(4),VALUE='Xtube_W', UVALUE='help_xtube_w')
;
wtmp = widget_button(wbase,VALUE='Set Parameters', UVALUE='SETPAR')
if sdep() EQ 'WINDOWS' then font = 'VERDANA*BOLD*ITALIC*24' else font = '-adobe-helvetica-bold-o-normal--18-180-75-75-p-104-iso8859-1'
wtmp = WIDGET_LABEL( wbase, FONT=font,VALUE=state.ifc.window_label)
wtmp = WIDGET_LABEL( wbase, FONT=font,VALUE='  '+state.ifc.about+'  ')
<end>menu

;
;=============================================================================
; parameter definitions
;=============================================================================
;
; this section contains the parameters for creating the set_parameters window
; in xop_ifc
; Note: Do not use continuation symbols
;
<start>parameters
100.0         |voltage
0.0           |ripple
0.0           | Al_filter
<end>parameters
;
;=============================================================================
; interface definitions
;=============================================================================
;
; this file contains the parameters for creating the interface with xop_ifc
; Note: ALL KEYWORDS MUST BE FILLED
; Note: Do not use continuation symbols
;
<start>interface
strarr(3)    |titles| [ 'Voltage 30<V<140 (kV)', 'Voltage ripple (%)','Al filter [mm]']
strarr(3)    |flags| [ '1', '1','1']
''            |title|               'Xtube_W'
''            |application|         'tasmip'
''            |window_label|        'Xtube_W'
''            |version|             '1.0'
''            |about|               ' X-ray generators (W) '
StrArr(2)     |rm|                  ['tasmip_tmp.dat','xtube_w_tmp.inp']
0             |ncol|                1
''            |run|                 'tasmip < xtube_w_tmp.inp'
0             |setWindowsHome|      0
<end>interface
;
;=============================================================================
; "write_inp" section: write input files instructions
;=============================================================================
;
;
<start>write_inp
openw, a1, 'xtube_w_tmp.inp', /get_lun
printf, a1, par.voltage
printf, a1, par.al_filter
printf, a1, par.ripple
free_lun, a1
<end>write_inp
;
;=============================================================================
; "plot" section: plotting results
;=============================================================================
;
;
<start>plot
Widget_Control,/HourGlass
IF (checkfile('tasmip_tmp.dat') NE 1) THEN a0 =widget_message(/ERROR,['xtube_w data not found...','Set Parameters before...  '])
IF (checkfile('tasmip_tmp.dat') EQ 1) THEN XPLOT,spec='tasmip_tmp.dat',GROUP=wsbase,xtitle='-1',ytitle='-1',wtitle='Xtube_W Results',title='#s'
<end>plot
;
;=============================================================================
; "view" section: show files
;=============================================================================
;
<start>view
IF (checkfile('tasmip_tmp.dat') NE 1) THEN a0 =widget_message(/ERROR,['xtube_w data not found...','Set Parameters before...  '])
IF (checkfile('tasmip_tmp.dat') EQ 1) THEN XDISPLAYFILE1,'tasmip_tmp.dat'
<end>view
;
;=============================================================================
; "write_f_optics" section: write files for xop/optics
;=============================================================================
;
<start>write_f_optics
a3 = checkfile('tasmip_tmp.dat')
IF ( a3 NE 1) THEN a0 =widget_message(/ERROR,['xtube_w data not found...','Set Parameters before...  '])
IF ( a3 EQ 1) THEN a0 = rascii('tasmip_tmp.dat')
; IF ( a3 EQ 1) THEN a0(1,*) = a0(1,*) *1000.0 / a0(0,*) ; bw from 1keV to 0.1%
IF ( a3 EQ 1) THEN a0(1,*) = a0(1,*) / a0(0,*) ; bw from 1keV to 0.1%
IF (a3 EQ 1) THEN a1 = a0
;IF (a3 EQ 1) THEN a1(1,*) = a1(1,*)*1.602189E-16
IF (a3 EQ 1) THEN a1(1,*) = a1(1,*)*physical_constants('ec')*1d3
IF (a3 EQ 1) THEN a0(0,*) = a0(0,*) ; *1000.0
IF (a3 EQ 1) THEN a1(0,*) = a1(0,*) ; *1000.0
IF (a3 EQ 1) THEN openw,a8,'SRCOMPE',/get_lun
IF (a3 EQ 1) THEN printf,a8,a0
IF (a3 EQ 1) THEN free_lun,a8
IF (a3 EQ 1) THEN openw,a8,'SRCOMPW',/get_lun
IF (a3 EQ 1) THEN printf,a8,a1
IF (a3 EQ 1) THEN free_lun,a8
IF (a3 EQ 1) THEN a8 = widget_message(/INFO,'Files SRCOMPE and SRCOMPW written to disk')
<end>write_f_optics
;
;=============================================================================
; "help" section: help for xws and ws
;=============================================================================
;
<start>help_xtube_w
a0 = sdep(/ds)
a1=getenv('XOP_HOME')+a0+'doc'+a0+'txt'+a0+'xtube_w.txt'
Xdisplayfile1,a1
<end>help_xtube_w
