;=============================================================================
; 
; this file is for being used with xop_ifc
;
; created: srio@esrf.fr 2009-06-19
;
; changed: 
;
;=============================================================================
;
;
;=============================================================================
; 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='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 Pattern',UVALUE='plot')
  wtmp= widget_button(w(3),VALUE='Plot Reflections',UVALUE='reflections')
  wtmp= widget_button(w(3),VALUE='Show parameters',UVALUE='view')

w(4) = widget_button(w(0),VALUE='Help', /Help)
  wtmp= widget_button(w(4),VALUE='xpowder_fml', UVALUE='help_xpowder_fml')
;
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
''       |File|            '?'
''       |Title|           'powder pattern using crysFML'
0.0      |Lambda|          1.540560
strarr(3)|job|             ['0','X rays','Neutrons']
0.0      |U|               0.0002
0.0      |V|               -0.0002
0.0      |W|               0.012
0.0      |X|               0.0019
0.0      |Ls|              1900.0
0.0      |ThMin|           1.0
0.0      |step|            0.05
0.0      |ThMax|           135.0
<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
; Note: use "run" = <none> for applications that do not use spawn
; Note: "ncol" is the number of columns in the XScrMenu screen
;
<start>interface
strarr(13)    |titles|              ['CIF File [? for Browser]: ','Title:','Lambda [A]: ','Radiation:','U: ','V: ','W: ', 'X: ','Ls:','TwoTheta from [deg]','TwoTheta step: ','TwoTheta to']
strarr(13)    |flags|               ['1','1','1','1','1','1','1','1','1','1','1','1','1'] 
''            |title|               'xpowder_fml'
''            |application|         'xpowder_fml'
''            |window_label|        'xpowder_fml'
''            |version|             '1.0'
''            |about|               '  Powder Diffraction Pattern '
StrArr(4)     |rm|                  ['xpowder_fml.par','xpowder_fml.inp','xpowder_fml.out','xpowder_fml.ref']
0             |ncol|                3
''            |run|                 'xpowder_fml < xpowder_fml.inp'
0             |setWindowsHome|      1
<end>interface
;
;=============================================================================
; "write_inp" section: write input files instructions
;=============================================================================
;
; This section is used to write the input file (mlayer.inp) for the
; mlayer application. It is used by xop_ifc
; Note: All lines are executed with the "execute" command of idl,
;       thus, no continuation symbolks are allowed
; Note: Input variables are in the "par" structure (which is defined 
;       in the file mlayer.parameters .
; Note: variables a0,...,a10 can be used for scratch calculations. No 
;       other variable names are allowed.
; Note: Use as many comment lines as you want.
;
<start>write_inp


file=par.file
IF StrCompress(file,/Remove_ALL) EQ '?' THEN file =Dialog_PickFile(/Read,Title='Select a cif File',Filter='*.cif')
IF CheckFile(file) EQ 0 THEN itmp = Dialog_Message(/Error,'File not found: '+file)

;
; write input file for Fortran xpowder_fml: xpowder_fml.inp
;
openw,a10,'xpowder_fml.inp',/get_lun

printf,a10,file
printf,a10,par.title
printf,a10,par.lambda
printf,a10,(par.job)[0]
printf,a10,par.u
printf,a10,par.v
printf,a10,par.w
printf,a10,par.x
printf,a10,par.Ls
printf,a10,par.thMin
printf,a10,par.step
printf,a10,par.thMax

free_lun,a10

delete_files,['xpowder_fml.par','xpowder_fml.out','xpowder_fml.ref']
<end>write_inp
;
;=============================================================================
; "plot" section: plotting results
;=============================================================================
;
;
; This section is used to plot the output data of the mlayer application.
; It is used by xop_ifc
; Note: All lines are executed with the "execute" command of idl,
;       thus, no continuation symbols are allowed
; Note: Input variables are in the "par" structure (which is defined 
;       in the file mlayer.parameters .
; Note: variables a0,...,a20 can be used for scratch calculations. No 
;       other variable names are allowed.
; Note: Use as many comment lines as you want.
;
<start>plot
Widget_Control,/HourGlass
IF (checkfile('xpowder_fml.out') NE 1) THEN a0 =widget_message(/ERROR,['xpowder_fml data not found...','Set Parameters before...  '])
tmp = read_textfile('xpowder_fml.inp')
XPLOT,spec="xpowder_fml.out",XTITLE='-1',ytitle='-1',TITLE=par.title,wtitle='xpowder_fml results from : '+tmp[0]
<end>plot

;
<start>reflections
Widget_Control,/HourGlass
IF (checkfile('xpowder_fml.ref') NE 1) THEN a0 =widget_message(/ERROR,['xpowder_fml data not found...','Set Parameters before...  '])
tmp = read_textfile('xpowder_fml.inp')
XPLOT,PARENT=p,spec="xpowder_fml.ref",YCOL=2,XTITLE='-1',ytitle='-1',TITLE=par.title,wtitle='xpowder_fml results from : '+tmp[0]
XPLOT_CONTROLS_ACTION,p,PSYMSIGN=1,PSYMBOL=11
<end>reflections

;
;=============================================================================
; "show" section: Edit/View file xpowder_fml.par
;=============================================================================
;
<start>view
Widget_Control,/HourGlass
XDisplayFile1,'xpowder_fml.par'
<end>view


;
;=============================================================================
; "help_xpowder_fml" section: help for xmlayer
;=============================================================================
;
<start>help_xpowder_fml
a0 = sdep(/ds)
a1=getenv('XOP_HOME')+a0+'doc'+a0+'txt'+a0+'xpowder_fml.txt'
Xdisplayfile1,a1
<end>help_xpowder_fml
