function   bcs_broad,Chan_struct,wave,bincal=bincal,ROCKW=ROCKW,	$
			Td6=Td6,DOPPW=DOPPW,TDOPPW=TDOPPW,OBSW=OBSW,	$	; Input data
			gauss=gauss,vel=vel,temp=temp				; Input switches
;+
; NAME:
;   bcs_broad
; PURPOSE:
;   Return Gaussian FWHM for a specified Doppler Temperature
;     or
;   Return the Doppler Temperature for a specified FWHM
;     or 
;   Return the Doppler Velocity
;
; CALLING SEQUENCE:
;                                                     -- In --
;   GAUSSW   = bcs_broad(Chan,ROCKW=ROCKW)           ; (Null)
;
;   Td6    = bcs_broad(Chan,wave,DOPPW=DOPPW)        ; DOPPW  (No GAUSSW)
;   Td6    = bcs_broad(Chan,wave,TDOPPW=TDOPPW)      ; TDOPPW (includes GAUSSW)
;   Td6    = bcs_broad(Chan,wave,OBSW=OBSW)          ; OBSW   (Observed FWHM)
;
;   TDOPPW = bcs_broad(Chan,wave,Td6=Td6,/Gauss)     ; Td6
;   TDOPPW = bcs_broad(Chan,wave,DOPPW=DOPPW,/Gauss) ; DOPPW  (No GAUSSW)
;   TDOPPW = bcs_broad(Chan,wave,OBSW=OBSW,/Gauss)   ; OBSW   (Observed FWHM)
;
;   Vel    = bcs_broad(Chan,wave,Td6=Td6,/vel)       ; Td6
;   Vel    = bcs_broad(Chan,wave,DOPPW=DOPPW,/vel)   ; DOPPW  (No GAUSSW)
;   Vel    = bcs_broad(Chan,wave,TDOPPW=TDOPPW,/vel) ; TDOPPW (includes GAUSSW)
;   Vel    = bcs_broad(Chan,wave,OBSW=OBSW,/vel)     ; OBSW   (Observed FWHM)
;   
; RETURNS:
;   Depending on the /vel, /Gauss or /Temp (default) control switches, returns
;   Td6 (Doppler Temperature in MK), TDOPPW (Ang, total Gaussian width) or
;   Vel (km/s, the Doppler velocity).
;
;   If only chan is specfied, then returns
;         GAUSSW   = (Ang)  Instrumental Gaussian Broadening (FWHM)
;
; INPUTS:
;   Chan     = BSC Channel structure or 
;              chan number (1 to 4)  1=Fe XXVI, 2=Fe XXV, 3=Ca XIX, 4= S XV
;              (Must be a scalar)
; OPTIONAL INPUTS:
;   wave     = The wavelength at which the quantity is desired (may be a vector)
;              (If not specified, uses w-line wavelength for requested channel)
; OPTIONAL INPUT KEYWORDS:
;   Input data (These are mutually exclusive)
;   Td6      = (MK)   Doppler Broadening Temperature
;   DOPPW    = (Ang)  Gaussian Broadening (doesn't include instrumental)
;   TDOPPW   = (Ang)  = sqrt( DOPPW^2 + GAUSSW^2 )
;   OBSW     = (Ang)  Observed FWHM of the Voight Profile
;
;   Control switches (These are mutually exclusive):
;   /Temp    = to return temperature (this is the default)
;   /Gauss   = to return TDOPPW
;   /Vel     = to return velocities
;
;  Note 1: Td6, DOPPW, TDOPPW, OBSW are mutually exclusive
;  Note 2: Td6, DOPPW, TDOPPW, and OBSW may be vectors, but must equal 
;          the length of wave or wave must be a scalar.
;  Note 3: /Temp, /Gauss, and /Vel are mutually exclusive
;
;
; OPTIONAL OUTPUT KEYWORDS:
;   ROCKW    = (Ang)  Crystal Rocking Curve (output)   (FWHM)
;   bincal   = The BCS calibration structure -- e.g., contains rocking width
;
; MODIFICATION HISTORY:
;   18-sep-93, J. R. Lemen (LPARL), Written.
;    4-Mar-94, Zarro (ARC) ensured that Td6 > 0
;-
on_error,2			; Return to caller

; --- Physical Constants
C_light = 3.e10			; (cm/s)    Speed light km/s
amu     = 1.66e-24		; (g)       Atomic Mass Unit (Chemical Scale)
k_bolt  = 1.38e-16		; (erg K-1) Boltzmann Const.
AMass = [0.,55.849,55.849,40.08,32.066]  ; Fe, Fe, Ca, S  (Chemical Scale)

if n_params() eq 0 then begin
   doc_library,'bcs_broad
   message,'Must supply at least one parameter'
endif 

Chan = gt_bsc_chan(chan_struct)
bincal = gt_bsc_bincal(chan_struct)
if n_elements(chan) gt 1 then message,'Chan must be a scalar'

ROCKW  = bincal.ROCKW			;(Ang) Always return this as an optional output keyword
GAUSSW = bincal.GAUSSW			;(Ang) Electronic Gaussian broadening

if n_params() eq 1   then $		; 1 Parameter ==>  Use default wavelength
	wave = get_atomic(chan_struct,/w)

  
; Check that Td6, DOPPW, TDOPPW, and OBSW are mutually exclusive

qtest =  (n_elements(Td6)<1) + (n_elements(DOPPW)<1) + (n_elements(TDOPPW)<1) + (n_elements(OBSW)<1)

if qtest eq 0 then return,Gaussw else $	; No parameters ==> return instrumental Gauss width
if qtest gt 1 then begin
    message,'Td6, DOPPW, TDOPPW, and OBSW are mutually exclusive',/cont
    message,'Make sure to specify only one of these parameters'
endif

qcase1 = [0,1,2,3] * [n_elements(Td6)<1,n_elements(DOPPW)<1,n_elements(TDOPPW)<1,n_elements(OBSW)<1]
qcase1 = max(qcase1)
npts   = n_elements(Td6) + n_elements(DOPPW) + n_elements(TDOPPW) + n_elements(OBSW)

qcase1_str = ['Td6','DOPPW','TDOPPW','OBSW']
qcase2_str = ['Td6','TDOPPW','Vel']

qtest = keyword_set(temp) + keyword_set(gauss) + keyword_set(vel)
if qtest eq 0 then qcase2 = 0 else $
if qtest gt 1 then begin
    message,', /temp, /gauss, and /vel are mutually exclusive',/cont
    message,'Make sure to specify only one of these switches'
endif else qcase2 = [0,1,2] * [keyword_set(temp), keyword_set(gauss), keyword_set(vel)]

qcase2 = max(qcase2)


;if keyword_set(verbose) then begin
;  print,'Input  data = ',qcase1_str(qcase1)
;  print,'Output data = ',qcase2_str(qcase2)
;endif

wvw = wave
if n_elements(wvw) eq 1 then wvw = wvw(0) else $
if (n_elements(wvw) ne npts) and (npts ne 1) then begin
   message,'Length of wave and '+qcase1_str(qcase1)+' must match',/cont
   message,'or the length of one or the other must be 1'
endif


case qcase1 of
  0: begin			; Td6 is the output

; Doppler Width = Wavelength * 2 * sqrt(alog(2)) * sqrt( 2 * k * Td / (m * c^2) )
      TTT = [wvw] * 2*sqrt(alog(2))*sqrt(2 * k_bolt / (Amass(chan) * amu * C_light^2))
      DOPPW = TTT # sqrt([Td6 > 0] * 1.e6)				; Make sure Td6 is a vector
      TDOPPW = sqrt( DOPPW^2 + Gaussw^2 )				; This is a matrix
     endcase

  1: begin			; DOPPW is the input
	TDOPPW = sqrt(DOPPW^2 + GAUSSW^2)
     endcase
  2: begin			; TDOPPW is the input
	DOPPW  = sqrt((TDOPPW^2 - GAUSSW^2)>0)
     endcase
  3: begin			; OBSW is the input
	TDOPPW = sqrt(OBSW*(OBSW-ROCKW)) * 2. * sqrt(alog(2.))
	DOPPW  = sqrt((TDOPPW^2 - GAUSSW^2)>0)
     endcase
endcase

  if n_elements(Td6) eq 0 then 		$
  Td6 = DOPPW^2 / wvw^2 / 1.e6 / 	$
	(4*alog(2)*2 * k_bolt / (Amass(chan) * amu * C_light^2))

  Vel = DOPPW / wvw * c_light/1.e5 / (2. * sqrt(alog(2.)))

case qcase2 of
  0: xx = Td6
  1: xx = TDOPPW
  2: xx = Vel
endcase
if n_elements(xx) eq 1 then xx = xx(0)
return,xx
end
