%N calget %F $MIR/src/subs/tabflux.for
%D Routine to retrieve an interpolated calibrator flux.
%P pjt
%: calibration, flux
%B
      subroutine calget(filename, source, freq, delfreq, day, deldate,
     *  flux, iostat)

      implicit none
      character filename*(*), source*(*)
      integer iostat
      real freq, delfreq, deldate, flux
      double precision day

 Input:
   filename The name of the flux calibrator file.  If this is a
            blank string, then it defaults first to the file
            pointed to by the environment variable $MIRFLUXTAB;
            second to the file ./FluxSource.cat; and, finally, to
            $MIRCAT/FluxSource.cat.   The old style cals.fluxes
            is still recognized, but deprecated since Miriad 4.1.0
   source   The name of the calibrator source to match.  No default.
   freq     The observation frequency (GHz) (default of 0.0 means
            that a match occurs at any frequency).
   delfreq  A range of frequency (in GHz) to bracket the freq
            parameter.  If ``freq'' is 0.0, then this term is ignored.
            The value of ``delfreq'' is used to range matching
            frequencies such that a match occurs when
            [freq-(delfreq/2) <= freq[table] <= freq+(delfreq/2)].
   day      The date of the observation to match (default is the
            current date).  If day is = 0, then the current date is
            used; if the date is less than the earliest matching date
            or later than the latest matching date, then the nearest
            matching date is used.  If neither of these apply, than the
            two nearest observation dates are used to interpolate the
            flux over time.  Day MUST be a Julian day number.
   deldate  A range of time (in Julian days) to bracket the date input.
            The value of ``deldate'' is used to range matching dates
            such that a match occurs when
            [day-(deldate/2) <= day[table] <= day+(deldate/2)].
   flux     The lower limit of fluxes to consider as a match
            (default is 0.0 and implies all matching fluxes).

 Output:
   source   The name of the first matched source.  This may not have
            the same value as on input.
   freq     The freq of the matched observation.  This may not
            have the same value as on input and has no relation to
            the determined flux value.  If the flux is interpolated
            over time between two values, then freq is set to 0.0 on
            output.
   day      The day of the matched observation.  This will not have
            the same value as on input, unless the flux is the
            interpolation between two values.
   flux     The flux of the matched observation.
   iostat   An error integer.  Iostat = 0 means no error;
            -1 if there are no data found in the file FileName;
            -2 if an EOF is reached before a match; -3 if no source
            name matchs; -4 if no match at desired characteristics;
            and -5 if the date of the latest flux measurement is
            offset by more than 4 years.
