;=============================================================================
; 
; this file is for being used with xop_ifc
;
; created: srio@esrf.fr 97-04-07
; Modified srio@esrf.fr 97-09-02 escape when error in Show...
; Modified srio@esrf.fr 97-10-02 sdep(), change some labels...
;=============================================================================
;
;=============================================================================
; 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='ws', UVALUE='help_ws')
;
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
'Wiggler A at APS'|title
7.0          |energy
100.0        |cur
8.50         |period
28.0         |n
0.00         |kx
8.74         |ky
1000.0       |emin
100000.0     |emax
2000L        |nee
30.0         |d
0.0          |xpc
0.0          |ypc
2.0          |xps
2.0          |yps
10L          |nxp
10L          |nyp
<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(17)    |titles| [ 'Title', 'Beam energy (GeV)', 'Beam current (mA)', 'Period (cm)', 'Number of periods', 'Kx', 'Ky', 'Min energy (eV)', 'Max energy (eV)', 'Number of energy steps', 'Distance (m)', 'X-pos. (mm)', 'Y-pos. (mm)', 'X slit [mm or mrad]', 'Y slit [mm or mrad]','Integration points X','Integration points Y']
strarr(17)    |flags| [ '1', '1', '1', '1', '1', '1','1', '1', '1', '1', '1', '1', '1','1','1','1','1']
''            |title|               'ws'
''            |application|         'ws'
''            |window_label|        'WS'
''            |version|             '1.5'
''            |about|               '   Wiggler Spectrum   '
StrArr(2)     |rm|                  ['ws.inp','ws.out']
0             |ncol|                0
0             |nrows|               4
''            |run|                 'ws'
0             |setWindowsHome|      0
<end>interface
;
;=============================================================================
; "write_inp" section: write input files instructions
;=============================================================================
;
;
<start>write_inp
a0 = {t1:'                              RING-ENERGY CURRENT', t2:'                      PERIOD N KX KY', t3:'                  EMIN EMAX NE', t4:'                      D XPC YPC XPS YPS NXP XYP', t5:'              MODE' } 
openw, a1, 'ws.inp', /get_lun
printf, a1, par.title, format='(a)'
printf, a1, par.energy, par.cur, a0.t1 , format="(2f8.2,a)"
printf, a1, par.period, par.n, par.kx, par.ky, a0.t2 , format="(f8.2,f8.1,f8.3,f8.3,a)"
printf, a1, par.emin, par.emax, par.nee, a0.t3 , format="(2f10.1,i8,a)"
printf, a1, par.d, par.xpc, par.ypc,par.xps, par.yps,par.nxp, par.nyp, a0.t4 , format="(f8.1,4f8.3,2i4,a)"
printf, a1, '4          '+a0.t5
free_lun, a1
<end>write_inp
;
;=============================================================================
; "plot" section: plotting results
;=============================================================================
;
;
<start>plot
Widget_Control,/HourGlass
IF (checkfile('ws.out') NE 1) THEN a0 =widget_message(/ERROR,['ws data not found...','Set Parameters before...  '])
IF (checkfile('ws.out') EQ 1) THEN XPLOT,'ws.out',GROUP=wsbase,XTitle='-1',YTitle='-1',YCol=2,ColTitles=['Energy [eV]','Flux [ph/s/0.1%bw]','p1','p2','p3','p4'],WTitle='ws results: '+par.title
<end>plot
;
;=============================================================================
; "write_f_optics" section: write files for xop/optics
;=============================================================================
;
<start>view
IF (checkfile('ws.out') NE 1) THEN a0 =widget_message(/ERROR,['ws data not found...','Set Parameters before...  '])
IF (checkfile('ws.out') EQ 1) THEN XDISPLAYFILE1,'ws.out'
<end>view
;
;=============================================================================
; "write_f_optics" section: write files for xop/optics
;=============================================================================
;
<start>write_f_optics
itmp = widget_message(/error,'Not yet implemented.')
<end>write_f_optics
;
;=============================================================================
; "help" section: help for ws
;=============================================================================
;
<start>help_ws
a0 = sdep(/ds)
a1=getenv('XOP_HOME')+a0+'doc'+a0+'ws.txt'
Xdisplayfile1,a1
<end>help_ws
