;=============================================================================
; 
; this file is for being used with xop_ifc
;
; Bending Magnet application
;
; created: srio@esrf.fr 97-09-12
; modified:
;   97/10/01 srio@esrf.fr some fixes in the calculations, added
;            Show/View parameters, use sdep().
;   2002/04/23 srio@esrf.fr modifies it to include more accurate 
;             numerical values (physical constants and related parameters).
;   2002/05/13: substituted g_one() by ()*fintk53
;   2002/05/23: Added lambda scale, log points. Using npoints instead step.
;   2002/05/25: substituted ()*fintk53 by sync_g1()
;   2002/06/03: use of sync_ene and sync_ang to calculate spectra
; 
;=============================================================================
;
;=============================================================================
; 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 energy spectra',UVALUE='plot')
  wtmp= widget_button(w(3),VALUE='Plot angular distribution (all wavelengths)',UVALUE='ang_all')
  wtmp= widget_button(w(3),VALUE='Plot angular distribution (one wavelength)',UVALUE='ang_single')
  wtmp= widget_button(w(3),VALUE='2D plot flux (angular,energy) distribution',UVALUE='surf_plot_flux')
  wtmp= widget_button(w(3),VALUE='2D plot power (angular,energy) distribution',UVALUE='surf_plot_power')
  wtmp= widget_button(w(3),VALUE='View numerical values',UVALUE='view')
w(4) = widget_button(w(0),VALUE='Help', /Help)
  wtmp= widget_button(w(4),VALUE='bm', UVALUE='help_bm')
;
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
'ESRF bending magnet' |MACHINE_NAME
strarr(3)    |RB_CHOICE|    ['0','Magnetic Radius','Magnetic Field']
25.0         |MACHINE_R_M
0.8          |BFIELD_T
6.04         |BEAM_ENERGY_GEV
0.1          |CURRENT_A
1.0          |HOR_DIV_MRAD
strarr(5)    |VER_DIV|    ['0','Full (integrated in Psi)','At Psi=0','In [PsiMin,PsiMax]','At Psi=Psi_Min']
100.0        |PHOT_ENERGY_MIN
100000.0     |PHOT_ENERGY_MAX
200L         |NPOINTS
strarr(3)    |LOG_CHOICE|    ['1','Lin','Log']
1.0          |PSI_MRAD_PLOT
-1.0         |PSI_MIN
1.0          |PSI_MAX
50           |PSI_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(16)    |titles| ['Machine name','B from:','Machine Radius [m]','Magnetic Field [T]','Beam energy [GeV]','Beam Current [A]','Horizontal div Theta [mrad]','Psi (vertical div) for energy spectra','Min Photon Energy [eV]','Max Photon Energy [eV]','Number of energy points','Separation between energy points','Max Psi[mrad] for angular plots','Psi min [mrad]','Psi max [mrad]','Number of Psi points']
strarr(16)    |flags| ['1','1','w(1) EQ 0','w(1) EQ 1','1','1','1','1','1','1','1','1','1','w(7) GE 2','w(7) EQ 2','w(7) EQ 2']
''            |title|               'bm'
''            |application|         'bm'
''            |window_label|        'BM'
''            |version|             '1.1'
''            |about|               '  Bending Magnet Radiation  '
''            |rm|                  ''
0             |ncol|                2
''            |run|                 '<none>'
0             |setWindowsHome|      0
<end>interface
;
;=============================================================================
; "plot" section: plotting results
;=============================================================================
;
;
<start>plot
Widget_Control,/HourGlass

a1 = MakeArray1(par.NPoints,par.PHOT_ENERGY_MIN,par.PHOT_ENERGY_MAX,Log=Fix(par.Log_Choice[0]))
a0 = par.BEAM_ENERGY_GEV*1d3/Physical_Constants('MEE') ; gamma
a2 = par.MACHINE_R_M
a3 = par.BFIELD_T
if strcompress(par.RB_CHOICE(0),/rem) EQ '0' then a3 = 1d9/physical_constants('c')*par.BEAM_ENERGY_GEV/par.MACHINE_R_M
if strcompress(par.RB_CHOICE(0),/rem) EQ '1' then a2 = 1d9/physical_constants('c')*par.BEAM_ENERGY_GEV/par.BFIELD_T
a7 = 4.0*!dpi*a2/3.0/a0^3*1D10 ; critical wavelength in A
a4 =  Physical_Constants('HC')/a7 ; critical energy in eV


a5 = Sync_Ene(par.Ver_Div[0],a1,E_GeV=par.BEAM_ENERGY_GEV, I_A=par.CURRENT_A, HDIV_MRAD=par.HOR_DIV_MRAD, EC_eV=a4,Psi_Min=par.Psi_Min,Psi_Max=par.Psi_Max,Psi_NPoints=par.Psi_NPoints)
a5par = Sync_Ene(par.Ver_Div[0],a1,E_GeV=par.BEAM_ENERGY_GEV, I_A=par.CURRENT_A, HDIV_MRAD=par.HOR_DIV_MRAD, EC_eV=a4,Pol=1,Psi_Min=par.Psi_Min,Psi_Max=par.Psi_Max,Psi_NPoints=par.Psi_NPoints)
a5per = Sync_Ene(par.Ver_Div[0],a1,E_GeV=par.BEAM_ENERGY_GEV, I_A=par.CURRENT_A, HDIV_MRAD=par.HOR_DIV_MRAD, EC_eV=a4,Pol=2,Psi_Min=par.Psi_Min,Psi_Max=par.Psi_Max,Psi_NPoints=par.Psi_NPoints)

IF StrCompress(par.Ver_Div[0],/Rem) EQ '0' THEN coltitles=['Photon Energy [eV]','Photon Wavelength [A]','E/Ec','Flux_spol/Flux_total','Flux_ppol/Flux_total','Flux[Phot/sec/0.1%bw]','Power[Watts/eV]']
IF StrCompress(par.Ver_Div[0],/Rem) EQ '1' THEN coltitles=['Photon Energy [eV]','Photon Wavelength [A]','E/Ec','Flux_spol/Flux_total','Flux_ppol/Flux_total','Flux[Phot/sec/0.1%bw/mradPsi]','Power[Watts/eV/mradPsi]']
IF StrCompress(par.Ver_Div[0],/Rem) EQ '2' THEN coltitles=['Photon Energy [eV]','Photon Wavelength [A]','E/Ec','Flux_spol/Flux_total','Flux_ppol/Flux_total','Flux[Phot/sec/0.1%bw]','Power[Watts/eV]']
IF StrCompress(par.Ver_Div[0],/Rem) EQ '3' THEN coltitles=['Photon Energy [eV]','Photon Wavelength [A]','E/Ec','Flux_spol/Flux_total','Flux_ppol/Flux_total','Flux[Phot/sec/0.1%bw/mradPsi]','Power[Watts/eV/mradPsi]']

IF StrCompress(par.Ver_Div[0],/Rem) EQ '0' THEN title='integrated in Psi,'
IF StrCompress(par.Ver_Div[0],/Rem) EQ '1' THEN title='at Psi=0,'
IF StrCompress(par.Ver_Div[0],/Rem) EQ '2' THEN title='in Psi=['+StrCompress(par.Psi_Min,/Rem)+','+StrCompress(par.Psi_max,/Rem)+'],'
IF StrCompress(par.Ver_Div[0],/Rem) EQ '3' THEN title='at Psi='+StrCompress(par.Psi_Min,/Rem)+','

a6=fltarr(7,n_elements(a1))

a6(0,*) = reform(a1)
a6(1,*) = Physical_Constants('HC')/reform(a1)
a6(2,*) = reform(a1)/a4 ; E/Ec
a6(3,*) = reform(a5par)/reform(a5)
a6(4,*) = reform(a5per)/reform(a5)
a6(5,*) = reform(a5)
a6(6,*) = reform(a5)*1d3*Physical_Constants('ec')

xplot,a6,xlog=Fix(par.Log_Choice[0]),ylog=Fix(par.Log_Choice[0]),coltitles=coltitles,Ycol=6,xtitle='-1',ytitle='-1',wtitle='BM results, '+title+' '+par.MACHINE_NAME
<end>plot


;
;
;=============================================================================
; "surf_plot_power" section: plotting results
;=============================================================================
;
;
<start>surf_plot_power
Widget_Control,/HourGlass

IF StrCompress(par.Ver_Div[0],/Rem) NE '2' THEN tmp = Widget_Message(/Error,'Please define [Psi_Min,Psi_Max] angular interval.')

a1 = MakeArray1(par.NPoints,par.PHOT_ENERGY_MIN,par.PHOT_ENERGY_MAX,Log=Fix(par.Log_Choice[0]))
a0 = par.BEAM_ENERGY_GEV*1d3/Physical_Constants('MEE') ; gamma
a2 = par.MACHINE_R_M
a3 = par.BFIELD_T
if strcompress(par.RB_CHOICE(0),/rem) EQ '0' then a3 = 1d9/physical_constants('c')*par.BEAM_ENERGY_GEV/par.MACHINE_R_M
if strcompress(par.RB_CHOICE(0),/rem) EQ '1' then a2 = 1d9/physical_constants('c')*par.BEAM_ENERGY_GEV/par.BFIELD_T
a7 = 4.0*!dpi*a2/3.0/a0^3*1D10 ; critical wavelength in A
a4 =  Physical_Constants('HC')/a7 ; critical energy in eV


a5 = Sync_Ene(2,a1,E_GeV=par.BEAM_ENERGY_GEV, I_A=par.CURRENT_A, HDIV_MRAD=par.HOR_DIV_MRAD, EC_eV=a4,Psi_Min=par.Psi_Min,Psi_Max=par.Psi_Max,Psi_NPoints=par.Psi_NPoints,FM=fm,Angle=angle_mrad)

;XSurface1,fm,angle_mrad,a1,Xtitle='Angle [mrad]',YTitle='Energy [eV]',ZTitle='Flux [photons/sec/0.1%bw/mradPsi]',WTitle='BM results: Flux versus angle and energy'
a5 =  fm*1d3*physical_constants('ec')
XSurface1,a5,angle_mrad,a1,Xtitle='Angle [mrad]',YTitle='Energy [eV]',ZTitle='Spectrap power[Watts/eV/mradPsi]',WTitle='BM results: Power versus angle and energy'
<end>surf_plot_power

;
;
;=============================================================================
; "surf_plot_flux" section: plotting results
;=============================================================================
;
;
<start>surf_plot_flux
Widget_Control,/HourGlass

IF StrCompress(par.Ver_Div[0],/Rem) NE '2' THEN tmp = Widget_Message(/Error,'Please define [Psi_Min,Psi_Max] angular interval.')

a1 = MakeArray1(par.NPoints,par.PHOT_ENERGY_MIN,par.PHOT_ENERGY_MAX,Log=Fix(par.Log_Choice[0]))
a0 = par.BEAM_ENERGY_GEV*1d3/Physical_Constants('MEE') ; gamma
a2 = par.MACHINE_R_M
a3 = par.BFIELD_T
if strcompress(par.RB_CHOICE(0),/rem) EQ '0' then a3 = 1d9/physical_constants('c')*par.BEAM_ENERGY_GEV/par.MACHINE_R_M
if strcompress(par.RB_CHOICE(0),/rem) EQ '1' then a2 = 1d9/physical_constants('c')*par.BEAM_ENERGY_GEV/par.BFIELD_T
a7 = 4.0*!dpi*a2/3.0/a0^3*1D10 ; critical wavelength in A
a4 =  Physical_Constants('HC')/a7 ; critical energy in eV


a5 = Sync_Ene(2,a1,E_GeV=par.BEAM_ENERGY_GEV, I_A=par.CURRENT_A, HDIV_MRAD=par.HOR_DIV_MRAD, EC_eV=a4,Psi_Min=par.Psi_Min,Psi_Max=par.Psi_Max,Psi_NPoints=par.Psi_NPoints,FM=fm,Angle=angle_mrad)

XSurface1,fm,angle_mrad,a1,Xtitle='Angle [mrad]',YTitle='Energy [eV]',ZTitle='Flux [photons/sec/0.1%bw/mradPsi]',WTitle='BM results: Flux versus angle and energy'
;a5 =  fm*1d3*physical_constants('ec')
;XSurface1,a5,angle_mrad,a1,Xtitle='Angle [mrad]',YTitle='Energy [eV]',ZTitle='Spectrap power[Watts/eV/mradPsi]',WTitle='BM results: Power versus angle and energy'
<end>surf_plot_flux

;
;=============================================================================
; "view" Show/View Results menu
;=============================================================================
;
<start>view
a0 = par.BEAM_ENERGY_GEV*1d3/Physical_Constants('MEE') ; gamma
a2 = par.MACHINE_R_M
a3 = par.BFIELD_T
if strcompress(par.RB_CHOICE(0),/REM) EQ '0' then a3 = 1d9/physical_constants('c')*par.BEAM_ENERGY_GEV/par.MACHINE_R_M
if strcompress(par.RB_CHOICE(0),/REM) EQ '1' then a2 = 1d9/physical_constants('c')*par.BEAM_ENERGY_GEV/par.BFIELD_T
a7 = 4.0*!dpi*a2/3.0/a0^3*1D10
a8 = 12d18*!dpi*physical_constants('ec')/(physical_constants('mee')^4) ; = 88.58...
;a4 = 2220.0*par.HOR_DIV_MRAD*par.BEAM_ENERGY_GEV^3/a2
a4 =  Physical_Constants('HC')/a7
a6 = [' ','Results of BM(XOP): '+par.MACHINE_NAME,' ']
a6 = [a6,'-------------------------------------------------------------']
a6 = [a6,'Magnetic radius       rho [m] = '+strcompress(a2,/rem)]
a6 = [a6,'Magnetic Field        Bo [T]  = '+strcompress(a3,/rem)]
a6 = [a6,'E/(m c^2)             gamma   = '+strcompress(a0,/rem)]
a6 = [a6,'Beam Energy           E [GeV] = '+strcompress(par.BEAM_ENERGY_GEV,/rem)]
a6 = [a6,'Beam current          I [A]   = '+strcompress(par.CURRENT_A,/rem)]
a6 = [a6,'-------------------------------------------------------------']
a6 = [a6,'Critical Energy       Ec [Ev]       = '+strcompress(a4,/rem)]
a6 = [a6,'Critical Wavelength   Wc [A]        = '+strcompress(Physical_Constants('HC')/a4,/rem)]
a6 = [a6,'Total Power (in 2 pi) [kWatts/A]    = '+strcompress(a8*par.BEAM_ENERGY_GEV^4/a2,/rem)]
a6 = [a6,'Total Power (in 2 pi) [kWatts]      = '+strcompress(a8*par.BEAM_ENERGY_GEV^4*par.CURRENT_A/a2,/rem)]
a6 = [a6,'Total Power (per mrad)[Watts/mrad]  = '+strcompress(a8*par.BEAM_ENERGY_GEV^4*par.CURRENT_A/a2/2.0/!dpi,/rem)]
a6 = [a6,'Total Power (in H accept) [Watts]   = '+strcompress(a8*par.BEAM_ENERGY_GEV^4*par.CURRENT_A/a2/2.0/!dpi*par.HOR_DIV_MRAD,/rem)]
a6 = [a6,'-------------------------------------------------------------']
Xdisplayfile1,text=a6,title='BM results'
<end>view
;
;=============================================================================
; "write_f_optics" section: write files for xop/optics
;=============================================================================
;
<start>write_f_optics

;a0 = ((par.PHOT_ENERGY_MAX - par.PHOT_ENERGY_MIN)/par.PHOT_ENERGY_STEP)+1
;a1 = findgen(a0)*par.PHOT_ENERGY_STEP + par.PHOT_ENERGY_MIN
a1 = MakeArray1(par.NPoints,par.PHOT_ENERGY_MIN,par.PHOT_ENERGY_MAX,Log=Fix(par.Log_Choice[0]))
a0 = par.BEAM_ENERGY_GEV*1d3/Physical_Constants('MEE') ; gamma
a2 = par.MACHINE_R_M
a3 = par.BFIELD_T
if strcompress(par.RB_CHOICE(0),/rem) EQ '0' then a3 = 1d9/physical_constants('c')*par.BEAM_ENERGY_GEV/par.MACHINE_R_M
if strcompress(par.RB_CHOICE(0),/rem) EQ '1' then a2 = 1d9/physical_constants('c')*par.BEAM_ENERGY_GEV/par.BFIELD_T
a7 = 4.0*!dpi*a2/3.0/a0^3*1D10
a4 =  Physical_Constants('HC')/a7

a5 = Sync_Ene(par.Ver_Div[0],a1,E_GeV=par.BEAM_ENERGY_GEV, I_A=par.CURRENT_A, HDIV_MRAD=par.HOR_DIV_MRAD, EC_eV=a4,Psi_Min=par.Psi_Min,Psi_Max=par.Psi_Max,Psi_NPoints=par.Psi_NPoints)

tmpadd=']'
IF StrCompress(par.Ver_Div[0],/Rem) EQ '1' THEN tmpadd='/mrad]' 
IF StrCompress(par.Ver_Div[0],/Rem) EQ '3' THEN tmpadd='/mrad]' 

a6=fltarr(2,n_elements(a1))
a7=fltarr(2,n_elements(a1))
a6(0,*) = reform(a1)
a7(0,*) = reform(a1)
a6(1,*) = reform(a5)
a7(1,*) = reform(a5)*1d3*physical_constants('ec')
openw,a8,'SRCOMPE',/get_lun
printf,a8,'!    File written by Xop/BM containig a Bending Magnet spectrum'
printf,a8,'!    Column 1:  Photon Energy [eV] Column 2: Flux[Photons/sec/0.1%bw'+tmpadd
printf,a8,'!    '
printf,a8,'!    The next commented lines include the inputs for XOP/BM'
printf,a8,'!    Save these lines to a file (e.g., bm.xop) and removed the !  symbols'
printf,a8,'!    Then you can load it in Xop/BM  '
printf,a8,"!; xop/xop_ifc,'bm'(v"+ifc.version+") input file on "+SysTime()
printf,a8,'!'+Write_Str(par)
printf,a8,'!    '
printf,a8,a6
free_lun,a8
openw,a8,'SRCOMPW',/get_lun
printf,a8,'!    File written by Xop/BM containig a Bending Magnet spectrum'
printf,a8,'!    Column 1:  Photon Energy [eV] Column 2: Spectral power [Watts/eV'+tmpadd
printf,a8,'!    '
printf,a8,'!    The next commented lines include the inputs for XOP/BM'
printf,a8,'!    Save these lines to a file (e.g., bm.xop) and removed the !  symbols'
printf,a8,'!    Then you can load it in Xop/BM  '
printf,a8,"!; xop/xop_ifc,'bm'(v"+ifc.version+") input file on "+SysTime()
printf,a8,'!'+Write_Str(par)
printf,a8,'!    '
printf,a8,a7
free_lun,a8
a8 = Widget_Message(/Question,['Files SRCOMPE and SRCOMPW contaning the','Flux and Power spectra, respectively, written to disk.','They can be used for optics calculation with Xop|Optics|XPower',' ','Do you want to plot them [for checking purposes]?'])
IF a8 EQ 'Yes' THEN Xplot,/no_block,'SRCOMPE',Title='File: SRCOMPE',XTitle='Photon energy [eV]',YTitle='Flux[Photons/sec/0.1%bw'+tmpadd
IF a8 EQ 'Yes' THEN Xplot,/no_block,'SRCOMPW',Title='File: SRCOMPW',XTitle='Photon energy [eV]',YTitle='Spectral power [Watts/eV'+tmpadd

<end>write_f_optics
;
;=============================================================================
; "help" section: help for bm 
;=============================================================================
;
<start>help_bm
a0 = sdep(/ds)
a1=getenv('XOP_HOME')+a0+'doc'+a0+'bm.doc'
Xdisplayfile1,a1
<end>help_bm
;
;=============================================================================
; "ang_all" section: Angular distribution over full wavelengths
;=============================================================================
;
<start>ang_all
a0 = par.BEAM_ENERGY_GEV*1d3/Physical_Constants('MEE') ; gamma
a2 = par.MACHINE_R_M ; will be R
a3 = par.BFIELD_T ; will be B
if strcompress(par.RB_CHOICE(0),/rem) EQ '0' then a3 = 1d9/physical_constants('c')*par.BEAM_ENERGY_GEV/par.MACHINE_R_M
if strcompress(par.RB_CHOICE(0),/rem) EQ '1' then a2 = 1d9/physical_constants('c')*par.BEAM_ENERGY_GEV/par.BFIELD_T
a7 = 4.0*!dpi*a2/3.0/a0^3*1D10 ; critical wavelength in A
a4 =  Physical_Constants('HC')/a7 ; critical energy in eV

a9 = MakeArray1(par.NPoints,-par.PSI_MRAD_PLOT,par.PSI_MRAD_PLOT)
a10 = DblArr(6,par.Npoints)
a10[0,*]=a9 ; angle in mrad
a10[1,*]=a9*a0/1d3 ; Psi[rad]*Gamma
a10[2,*]=sync_f(a9*a0/1d3)
a10[3,*]=sync_f(a9*a0/1d3,Pol=1)
a10[4,*]=sync_f(a9*a0/1d3,Pol=2)
a10[5,*]=sync_ang(0,a9,I_A=par.CURRENT_A,HDiv_mrad=par.HOR_DIV_MRAD,E_GeV=par.BEAM_ENERGY_GEV,R_M=a2)

coltitles=['Psi[mrad]','Psi[rad]*Gamma','F','F s-pol','F p-pol','Power[Watts/mrad(Psi)]']

xplot,a10,coltitles=coltitles,xtitle='-1',ytitle='-1',wtitle='BM results: Angular distribution (all wavelengths) '+par.MACHINE_NAME

<end>ang_all

;
;=============================================================================
; "ang_single" section: Angular distribution for a single wavelengths
;=============================================================================
;
<start>ang_single
a0 = par.BEAM_ENERGY_GEV*1d3/Physical_Constants('MEE') ; gamma
a2 = par.MACHINE_R_M ; will be R
a3 = par.BFIELD_T ; will be B
if strcompress(par.RB_CHOICE(0),/rem) EQ '0' then a3 = 1d9/physical_constants('c')*par.BEAM_ENERGY_GEV/par.MACHINE_R_M
if strcompress(par.RB_CHOICE(0),/rem) EQ '1' then a2 = 1d9/physical_constants('c')*par.BEAM_ENERGY_GEV/par.BFIELD_T
a7 = 4.0*!dpi*a2/3.0/a0^3*1D10 ; critical wavelength in A
a4 =  Physical_Constants('HC')/a7 ; critical energy in eV

a8 = physical_constants('ec')/(physical_constants('mee'))^2/physical_constants('h')*(9d-2/2/!dpi) ; 1.3264d13
a9 = MakeArray1(par.NPoints,-par.PSI_MRAD_PLOT,par.PSI_MRAD_PLOT)
a10 = DblArr(7,par.Npoints)

a10[0,*]=a9 ; angle in mrad
a10[1,*]=a9*a0/1d3 ; Psi[rad]*Gamma
a10[2,*]=sync_f(a9*a0/1d3,par.PHOT_ENERGY_MIN/a4)
a10[3,*]=sync_f(a9*a0/1d3,par.PHOT_ENERGY_MIN/a4,Pol=1)
a10[4,*]=sync_f(a9*a0/1d3,par.PHOT_ENERGY_MIN/a4,Pol=2)
a10[5,*]=sync_ang(1,a9,Energy=par.PHOT_ENERGY_MIN,I_A=par.CURRENT_A,HDIV_MRAD=par.HOR_DIV_MRAD,E_GEV=par.BEAM_ENERGY_GEV,EC_EV=a4)
a10[6,*]=a10[5,*]*1d3*physical_constants('ec') ; Power density

coltitles=['Psi[mrad]','Psi[rad]*Gamma','F','F s-pol','F p-pol','Flux[Ph/sec/0.1%bw/mradPsi]','Power[Watts/eV/mradPsi]']

xplot,a10,coltitles=coltitles,Ycol=6,xtitle='-1',ytitle='-1',wtitle='BM results: Angular distribution at Energy = '+StrCompress(par.PHOT_ENERGY_MIN,/Rem)+' eV'

<end>ang_single
