;+
; NAME:
;     CALSPEC
; PURPOSE:
;     Returns the flux spectrum, in Jy, of several main total power calibrator
;     sources, Cas A, Cyg A, Tau A and Vir A.
; CATEGORY:
;     OVRO APC DATA CALIBRATION
; CALLING SEQUENCE:
;     flux = calspec(srcname,epoch)
; INPUTS:
;     srcname    One of the 4 standard source names.  A string (all caps)
;                  as follows: 'CASA', 'CYGA', 'TAUA', 'VIRA'
;     epoch      The approximate date as decimal year.  This argument
;                  is needed only for Cas A, since only it has a secular
;                  decrement.
; OPTIONAL (KEYWORD) INPUT PARAMETERS:
; ROUTINES CALLED:
; OUTPUTS:
;     flux       The flux spectrum (at every harmonic, 5-90) of the
;                  source specified.
; COMMENTS:
;     There will have to be modifications to this routine when
;     additional antennas are available.
; SIDE EFFECTS:
; RESTRICTIONS:
;     This version assumes 27 m antennas.  It could conceivably be needed
;     for 2 m flux measurements, but would not give the correct answer unless
;     changes are made.
; MODIFICATION HISTORY:
;     Written 02-Aug-1998 by Dale E. Gary
;-

function calspec,srcname,epoch

   ; Cas A correction is now based on 20 GHz map made by Rick Perley at VLA.
   ; The actual map was convolved with the appropriate gaussian beam and the
   ; correction factor determined using IDL.  The correction factors are
   ; listed in the above DATA statement, in order from 1 to 18 GHz, in steps
   ; of 0.2 GHz.  DG  6/6/93

   casacor = [$
     0.995,0.992,0.990,0.987,0.984,0.980,0.976,0.972,0.968,0.963,0.957,$
     0.952,0.946,0.940,0.934,0.927,0.921,0.914,0.907,0.899,0.892,0.884,$
     0.876,0.868,0.860,0.852,0.843,0.835,0.826,0.817,0.808,0.800,0.791,$
     0.782,0.773,0.763,0.754,0.745,0.736,0.727,0.717,0.708,0.699,0.690,$
     0.680,0.671,0.662,0.653,0.644,0.635,0.626,0.617,0.608,0.599,0.590,$
     0.581,0.572,0.564,0.555,0.547,0.538,0.530,0.522,0.514,0.506,0.498,$
     0.490,0.482,0.474,0.467,0.459,0.452,0.444,0.437,0.430,0.423,0.416,$
     0.410,0.403,0.396,0.390,0.383,0.377,0.371,0.365,0.359]


   hpbwpar = 46.5   ; HPBW = hpbwpar/f  [arcmin/ghz]
   cygasep = 1.9    ; Cyg A separation [arcmin]
   tauafwhm = 3.7   ; Tau A FWHM [arcmin]
   virafwhm = 12    ; Vir A FWHM of extended part of source [arcmin]
   ; Array of standard frequencies, in GHz (all harmonics 5-90)
   f = (findgen(86)+5)*0.2
   hpbw = hpbwpar / f

   ; Calculates flux [Jy} of standard calibrators using empirical fits.
   ; Reference: BAARS ET AL, A&A 61, 99, 1977.

   ; Calculates correction factor for effect of single dish resolution of
   ; extended brightness distribution of standard calibrators.  Result
   ; is >0 and <=1.  Assumes gaussian beam.

   CASE srcname OF
     'CASA': BEGIN
          IF (n_elements(epoch) EQ 0) THEN BEGIN
             ans = widget_message('Must include an epoch (e.g. 1998.5) when '+$
                                  'source is Cas A',/error)
             return,-1
          ENDIF
          flux1980 = 2723. * f^(-0.77)
          secdecr = 1. - (epoch - 1980.) * (.0097 - .003 * alog10(f))
          calflux = flux1980*secdecr
          xsrcor = casacor(nint(f*5)-5)
          detflux = calflux*xsrcor
        END
     'CYGA': BEGIN
          calflux = 2685. * f^(-1.244)
          ; Two equal point sources, separated by a distance cygasep.
          xsrcor = exp(-0.69315 * (cygasep/hpbw)^2)
        END
     'TAUA': BEGIN
          calflux = 1042. * f^(-0.299)
          ; gaussian of FWHM tauafwhm
          xsrcor = hpbw^2 / (hpbw^2 + tauafwhm^2)
        END

     'VIRA': BEGIN
          calflux =  285. * f^(-0.856)
          ; Point core plus gaussian of FWHM virafwhm, with flux
          ; fraction 2.1715
          xsrcor = 1.0 - exp(-f/2.1715) * virafwhm^2 / (virafwhm^2 + hpbw^2)
        END
     ELSE: BEGIN
          ans = widget_message('No such source: '+srcname,/error)
          return,-1
        END
   ENDCASE

   ; Detected flux is the Calibrator flux times the flux correction due to
   ; overresolving the source.
   detflux = calflux*xsrcor

return,detflux
end
