
   ===========================  Xws   =========================

   Xws is an widget based graphical interface to calculate 
   spectral properties of a wiggler insertion device.

   The main window contains four buttons:

	QUIT: 	Exits from the program

	DATA:   Defines the parameters for the calculation

	SHOW:	Plots, Prints or Views the results

	HELP:	Shows the Xws help text or the WS help text

 -----------------------------------------------------------------------
	Author: Roger J. Dejus (dejus@anlaps.aps.anl.gov), APS, May, 1994.
	Modification history:
       96/01/19 MSR changes labels Xtransmit -> XOP/Optics
       97/01/23 MSR changes for Windows95, cosmetics (xhelp, widget_message...)
       97/02/05 MSR adds help button in parameters window.
       97/10/02 MSR uses sdep(), xop_wd and other cosmetics.
       00/07/17 MSR introduces ws 1.5 in the interface.


C+
C PROGRAM DESCRIPTION:	
C  Program to calculate wiggler and bending magnet spectra using the
C  Bessel function approximation. The program may be executed from the xop
C  interface.
C 
C AUTHORS: 
C  Roger J. Dejus
C  The Advanced Photon Source
C  Experimental Facilities Division
C  Argonne National Laboratory
C 
C CREATION DATE: 
C  17-FEB-1994
C 
C INPUT PARAMETERS:
C  The input parameters are divided into sections related to the storage ring,
C  the wiggler device, and the quantity to be calculated.
C Machine Parameters:
C  Storage ring energy 			(GeV)
C  Storage ring current			(mA)
C Wiggler Parameters:
C  Period length			(cm)
C  Number of periods
C Note: For a bending magnet source: set N=0.5, and make Ky large and adjust
C       the period length accordingly. For example, put Ky=9.34 and calculate
C       the period length from, Period (cm) = 10.0/B0(T), where B0 is the known
C       strength of the magnetic field (in Tesla) for the bending magnet.  The
C       calculated power density (pd) is correct, but the total power (ptot)
C       is irrelevant. Typically make the extend of the pinhole small in the
C	horizontal direction (theta << Ky/gamma) as the intensity should
C	not depend on the horizontal offset. Check value of B0 (and critcal
C	energy EC0) in the plot file.
C  Deflection parameter (hor.  field) Kx (= 0.0 only; for elliptical wiggler
C  not yet implemented)
C  Deflection parameter (vert. field) Ky
C Scan Parameters:
C  Minimum energy			(eV)
C  Maximum energy			(eV)
C  Number of energy points
C Pinhole Parameters:
C  Distance from the source		(m)
C    (d=0.0 => angular units)
C  X-coordinate for center of pinhole	(mm) or (mrad)
C  Y-coordinate for center of pinhole	(mm) or (mrad)
C  X-size of pinhole (full width)	(mm) or (mrad)
C  Y-size of pinhole (full width)	(mm) or (mrad)
C    (for angular units (d=0.0) values are entered in mrad)
C    (X is for horizontal direction)
C    (Y is for the vertical direction)
C  Number of subdivisions of pinhole in X (max 50)
C  Number of subdivisions of pinhole in Y (max 50)
C
C Mode:
C  Depending on the mode selected, some of the pinhole parameters may be
C  set to different values by the program; see the output file ws.plt.
C  MODE    1    Angular/spatial flux density distribution
C  MODE    2    Angular/spatial flux density spectrum
C  MODE    3    On-axis brilliance spectrum (not yet implemented)
C  MODE    4    Flux spectrum through a pinhole
C  MODE    5    Flux spectrum integrated over all angles
C  MODE    6    Power density and integrated power
C
C  Angular/spatial flux density distribution
C    - Flux distribution at the energy chosen as minimum energy.
C  Angular/spatial flux density spectrum
C    - Spectrum at any given point in space as selected by the X and Y
C      coordinate for the center of the pinhole. X is horizontal and Y is
C      vertical.
C  On-axis brilliance spectrum (not yet implemented)
C  Flux spectrum through a pinhole
C    - Spectrum through a pinhole centered at X-center and Y-center with
C      size X-size and Y-size.  The energy range is from the minimum to the
C      maximum energy.
C  Flux spectrum integrated over all angles (wiggler only).
C    -  The pinhole parameters have no significance here.
C  Power density and integrated power
C    -  Integrated over all energies, thus the energy parameters have no
C       significance here.
C
C Polarization:
C  The normalized Stokes parameters are calculated including the 
C  unpolarized component.
C
C DESIGN ISSUES:
C  Program calculates the spectra from the Modified Bessel functions.  See K.J.
C  Kim, in "Physics of Particle Accelerators", vol. 1, AIP Conference Proc. 184
C  Ed. R.G. Lerner, New York (1989), p. 583, Eq. (3.12).
C  The algorithm is based on a series expansion for small arguments Z
C  (Abramowitz & Stegun Eq. 9.6.2 and 9.6.10) and an asymptotic expansion for
C  large arguments (Eq. 9.7.2).
C  Reference: Handbook of Mathematical Functions, Eds. Milton Abramowitz and
C  Irene A. Stegun, Ninth Printing, Dover Publications, New York (1970).
C  NOTE: THE POLARIZATION PARAMETERS ARE PROVIDED ALTHOUGH NOT THOROUGHLY
C  TESTED - USE WITH CAUTION.
C  
C COPYRIGHT:
C  Unless part of the XOP software package, this routine must only be used 
C  at The Advanced Photon Source and must not be tranferred or used at any 
C  other location without the written consent of the author.
C  
C FILES USED:
C  Input file - ws.dat  File in the user's current directory containing the
C                       input parameters.
C  Output file - ws.plt File in the user's current directory containing the 
C                       results of the calculation.  The header contains
C                       all input parameters and the calculated on-axis first
C			harmonic energy (e1), corresponding wavelength (l1), 
C			total power (ptot), and the on-axis power density (pd).
C			See note above when using N=0.5 for bending magnet.
C KEYWORDS:
C  Wiggler Spectrum, Modified Bessel Function of Second kind.
C  
C LINK/LIBRARY ISSUES:
C  The gamma function is needed.  Currently uses no library routines. The values
C  for gamma(2/3) and gamma(1/3) are stored as constants. May be substituted by
C  calls to the NAG library routine S14AAF.
C  
C PORTABILITY ISSUES:
C  Runs on DEC 3000/400 AXP alpha (Tru64Unix v5.0), SUN (Solaris: SunOS
C  Release v5.6), and Windows 95/98/NT (Pentium and higher).
C  
C TIMING:
C  Execution time is typically very fast but depends on the quantity being
C  calculated. Typically seconds to at the most minutes.
C
C VERSION:
C  1.5
C  
C MODIFICATION HISTORY:
C 
C	 Date     | Name  | Description
C ----------------+-------+-----------------------------------------------------
C 17-JUL-2000     | RJD   | Adopted from v1.4 which was never released to the
C                 |       | public. Turned off circular polarization for the
C                 |       | wiggler (which is only valid for EMW). 
C                 |       | Current version is v1.5.
C ----------------+-------+-----------------------------------------------------
C [change_entry]
C-

