;=============================================================================
; 
; this file is for being used with xop_ifc
;
; Neutron reactors spectra application
;
; created: srio@esrf.fr 97-09-12 
; modified:
;   03/02/19 alianell@ill.fr adds references and more transparent parameters 
;   see the Neutron Data Booklet Chapter 3 - 1.2
;   01/07/19 boisseau@esrf.fr customized for Maxwell distribution (neutrons)
;   97/10/01 srio@esrf.fr some fixes in the calculations, added
;            Show/View parameters, use sdep().
;=============================================================================
;
;=============================================================================
; 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='NSources 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 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='NSources', UVALUE='help_nsources')
;
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
300.0        |TEMPERATURE
StrArr(4)    |ZONE| ['0','Thermal Neutrons','Epithermal Neutrons','Fast Neutrons']
2.0D14       |MAXFLUX_f
2.0D13       |MAXFLUX_epi
2.0D14       |MAXFLUX_th
500          |NPOINTS
<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(6)    |titles| ['Moderator temperature [K]','Spectrum','Max flux (fast) [n/cm2/s]','Max flux (epithermal) [n/cm2/s]','Max flux (thermal) [n/cm2/s]','Number of points ']
strarr(6)     |flags| ['1','1','w(1) EQ 2','w(1) EQ 1','w(1) EQ 0','1']
''            |title|               'nsources'
''            |application|         'nsources'
''            |window_label|        'Neutron reactor spectrum'
''            |version|             '1.0'
''            |about|               'NSources '
''            |rm|                  ''
0             |ncol|                1
''            |run|                 '<none>'
0             |setWindowsHome|      0
<end>interface
;
;=============================================================================
; "plot" section: plotting results
;=============================================================================
;
;
<start>plot
Widget_Control,/HourGlass
;KB=0.000086173                                        ;Boltzmann constant eV*K-1
KB=physical_constants('kb')/physical_constants('ec') ;Boltzmann constant meV*K-1=0.000086173
a0 = par.TEMPERATURE
a1 = KB*par.TEMPERATURE                               ;K*T in eV 
IF Fix(par.ZONE[0]) EQ 0 THEN a2 = MakeArray1(par.NPOINTS,0.00001,0.2) ; thermal
IF Fix(par.ZONE[0]) EQ 1 THEN a2 = MakeArray1(par.NPOINTS,100.,0.1d6)  ; epithermal
IF Fix(par.ZONE[0]) EQ 2 THEN a2 = MakeArray1(par.NPOINTS,0.5d6,4.5d6) ; fast 
a3 = dblarr(2,par.NPOINTS)
a3[0,*]=a2                         ; energy in eV    
IF Fix(par.ZONE[0]) EQ 0 THEN a3[1,*] = par.MAXFLUX_th*a2/a1*exp(-a2/a1)       ;thermal neutrons
IF Fix(par.ZONE[0]) EQ 1 THEN a3[1,*] = par.MAXFLUX_epi/a2                       ;epithermal
IF Fix(par.ZONE[0]) EQ 2 THEN a3[1,*] = par.MAXFLUX_f*exp(-a2*1.d-6*sinh(sqrt(2.*a2*1.d-6))) ;fast neutrons 
IF Fix(par.ZONE[0]) EQ 0 THEN title = 'thermal'
IF Fix(par.ZONE[0]) EQ 1 THEN title = 'epithermal'
IF Fix(par.ZONE[0]) EQ 2 THEN title = 'fast'
xplot,a3,coltitles=['Energy [eV]',title+' flux [n/s/cm^2]'],Ycol=2,xtitle='-1',ytitle='-1',title=title+' neutron flux' 
<end>plot
;
;=============================================================================
; "view" Show/View Results menu
;=============================================================================
;
<start>view
;KB=0.000086173                             ;Boltzmann constant meV*K-1
KB=physical_constants('kb')/physical_constants('ec') ;Boltzmann constant meV*K-1=0.000086173
a0 = par.TEMPERATURE
a1 = KB*par.TEMPERATURE                 ;K*T in eV 
a6 = [' ','Results of NEUTRON REACTOR SPECTRA (NOP/NSOURCES)',' ']
a6 = [a6,'-------------------------------------------------------------']
a6 = [a6,'Moderator temperature           T[K] = '+strcompress(a0,/rem)+', T[eV] = '+strcompress(a1,/rem)]
IF Fix(par.zone[0]) EQ 2 THEN a6 = [a6,'Maximum flux (fast)       [n/cm2/s]  = '+strcompress(par.MAXFLUX_f,/rem)]
IF Fix(par.zone[0]) EQ 1 THEN a6 = [a6,'Maximum flux (epithermal) [n/cm2/s]  = '+strcompress(par.MAXFLUX_epi,/rem)]
IF Fix(par.zone[0]) EQ 0 THEN a6 = [a6,'Maximum flux (thermal)    [n/cm2/s]  = '+strcompress(par.MAXFLUX_th,/rem)]
a6 = [a6,'-------------------------------------------------------------']
a6 = [a6,'Thermal neutron flux: Maxwellian distribution valid for E < 0.2 eV'] 
a6 = [a6,'Epithermal neutron flux: 0.2 eV < E < 0.5 MeV'] 
a6 = [a6,'Fast neutron flux: E > 0.5 MeV'] 
a6 = [a6,'-------------------------------------------------------------']
Xdisplayfile1,text=a6,title='nsources results'
<end>view
;
;=============================================================================
; "help" section: help for Maxwell distribution 
;=============================================================================
;
<start>help_nsources
a0 = sdep(/ds)
a1=getenv('XOP_HOME')+a0+'doc'+a0+'txt'+a0+'nsources.txt'
Xdisplayfile1,a1
<end>help_nsources
