!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Compute conversion factor between Jy/Beam and K (main beam).
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
define double nu theta[2]
!
! Different behavior depending on input parameter
if ("&1none".eq."none") then
   ! No input parameter => Ask user
   let nu /prompt "Enter Frequency [GHz]"
   let nu nu*1e9
   let theta /prompt "Enter FWHM Beam [Arcsec]"
   let theta theta*sec
else
   ! The input parameter is the variable name of a GDF image
   if ((&1%major.eq.0).or.(&1%minor.eq.0)) then
      message e jansky "No beam size => Impossible conversion"
      return base
   else
      let theta '&1%major' '&1%minor'
   endif
   let nu &1%restfre*1e6
endif
!
! kperjy will be used as a conversion factor outside
define double lambda
if .not.exist(kperjy) then
   define double kperjy jyperk /global
endif
!
! Real computation
let theta theta/2./sqrt(log(2.0))
let lambda 2.99792458e8/nu
let jyperk 2.0*1.38e3*pi*theta[1]*theta[2]/lambda^2
let kperjy 1/jyperk
!
! User Feedback
if ("&2none".eq."none") then
   say "Wavelength: "'nint(1e5*lambda)/100'" mm, Beam: "'nint(10*theta[1]/sec)/10'" x "'nint(10*theta[2]/sec)/10'
   say "K[Tmb] per Jy/Beam:  "'kperjy'
   say "mJy/beam per K[Tmb]: "'1e3*jyperk'
endif
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
