Viewing contents of file '../idllib/iuedac/iuelib/pro/fescalc.pro'
;******************************************************************************
;+
;*NAME:
;
;     	FESCALC.PRO     (IUE Production Library)
;
;*CLASS:
;
;	FES magnitude procedure
;
;*CATEGORY:
;
;*PURPOSE:
;
;	To calculate a target's V magnitude, based on its color index and FES
;	counts, using the Fireman and Imhoff (1989) calibration for the former
;	FES reference point (-16,-208).  To calculate a target's V magnitude, 
;	based on its color index, FES counts, and focus step, using Perez 
;	(1991) calibration for the current FES reference point (-144,-176).  
;	The new FES reference point was implemented on January 22,1990 at GSFC 
;	and on July 23, 1990 at VILSPA.
;
;*CALLING SEQUENCE:
;
;	FESCALC,COUNTS,FLAP,FESTSR,BMV,DATE,VFES,fstep,obsst
;
;*PARAMETERS:
;
;	COUNTS	(REQ) (I) (0) (I)
;               FES counts at current reference point 
;               (i.e. out of aperture)
;	
;	FLAP	(REQ) (I) (0) (I)
;  	        FES overlap/underlap flag.  Overlap = 0, underlap = 1.
;
;	FESTSR	(REQ) (I) (0) (I)
;        	FES track scan rate.  Fast Track = 0, Slow Track = 1.
;
;	BMV 	(REQ) (I) (0) (F)
;               B-V color index.
;
;	DATE	(REQ) (I) (0) (F)
;               Date of observation in decimal years.  Beware of dates near 
;		the chenge of reference points.  If the observing station is 
;		GSFC and the date is 1990.0602 (January 22, 1990) or greater
;		OR if the observing station is VILSPA and the date is 1990.558 
;		(July 23, 1990) or greater, then the calculation uses the 
;		information for the new FES reference point.
;	
;	VFES	(REQ) (O) (0) (F)
;               FES magnitude, corrected for FES degradation and dead 
;               time, as well as B-V color correction.
;
;	FSTEP	(OPT) (I)
;		The focus step.  Required for new reference point data.  
;		If not given, defaults to -2.653; thus, the corrected counts 
;		equals the observed counts.
;
;	OBSST	(OPT) (I)
;		Observing station.  Required for new reference point
;		data.  If not given, defaults to GSFC.  
;		GSFC = 'G', Vilspa = 'V'.
;
;*EXAMPLES:
;
;	Calculate the FES magnitude for a target with 1000 counts, F/O, 
;       on 1989 April 17, which has a B-V color index of 0.5.
;		FESCALC,1000,0,0,0.5,1989.29,VFES
;
;
;*SYSTEM VARIABLES USED:
;
;	!NOPRINT
;
;*INTERACTIVE INPUT:
;
;*SUBROUTINES CALLED:
;
;       PARCHECK - parameter checking
;
;*FILES USED:
;
;*SIDE EFFECTS:
;
;*RESTRICTIONS:
;
;	This "calibration is NOT valid for FES data taken during the 'FES
;	anomaly' experienced after January 22, 1991, where additional 
;	background scattered light was detected in the FES mainly at high
;	beta attitudes." As of February 1991, "this background has been
;	reported to decrease substantially since its initial detection."
;	(Perez 1991)
;
;*NOTES:
;
;	For the former FES reference point (-16,-208):
;	   Assumes no degradation correction is needed until a specific "cutoff 
;	date", after which, a linear degradation in used.  Separate 
;	calibrations are used for underlap and overlap measurements.  The 
;	overlap date is 1981.65, while it is 1980.60 for underlap. 
;          Based on Imhoff (1986) IUE NASA Newsletter 29, p. 45.
;
;	For the current FES reference point (-144,-176):
;	   Assumes no degradation correction is needed.  Corrects for 
;	focus step.
;          Based on Perez (1991) IUE NASA Newsletter 45, p. 19.
;
;	Beware of dates near the change of reference points.  If the observing 
;	station is GSFC and the date is 1990.0602 (January 22, 1990) or greater
;	OR if the observing station is VILSPA and the date is 1990.558 (July 
;	23, 1990) or greater, then the calculation uses the information for 
;	the new FES reference point.
;
;       tested with IDL Version 2.1.0 (sunos sparc)	11 Jul 91
;       tested with IDL Version 2.1.0 (ultrix mispel)	N/A
;       tested with IDL Version 2.1.0 (vms vax)		8 July 1991
;
;*PROCEDURES:
;
;	For the former FES reference point (-16,-208):
;	   An FES magnitude is calculated based on user supplied FES counts and 
;	B-V color index.  The calculation uses the FES calibration of Fireman 
;	and Imhoff (1989) to compensate for the FES's degradation with time.
;
;	For the current FES reference point (-144,-176):
;	   An FES magnitude is calculated based on user supplied FES counts, 
;	B-V color index, focus step, and observing station.  The calculation 
;	uses the FES calibration of Perez (1991) for the focus dependency.  
;	Also, new K values are used. Default values for observing station 
;	(GSFC) and focus step (-2.653) are used, if no values are given.
;
;I_HELP nn:
;
;*MODIFICATION HISTORY:
;
;	Original version written 1989 Apr 17, by T. J. Teays.
;	 2-21-91 PJL moved to sun/unix system; added warning concerning
;		     the change of the reference point
;	 3-12-91 PJL updated with Perez (1991) information
;	 8- 7-91 LLT tested on VAX; updated prolog
;	11- 7-91 PJL cleaned up; tested on SUN; updated prolog
;
;-
;*******************************************************************************
 pro fescalc,counts,flap,festsr,bmv,date,vfes,fstep,obsst
;
; check parameters
;
 npar = n_params(0)
 if npar eq 0 then begin
    print,'FESCALC,COUNTS,FLAP,FESTSR,BMV,DATE,VFES,fstep,obsst'
    retall
 endif  ; npar
 parcheck,npar,[6,7,8],'FESCALC'
;
 if (npar eq 6) then begin
    obsst = 'G'
    fstep = -2.653
 endif  ; npar eq 6
;
 if (npar eq 7) then begin
    check = size(fstep)
    if check(1) eq 7 then begin
       obsst = fstep
       fstep = -2.653
    endif else obsst = 'G'
 endif  ; npar eq 7
;
 obsst = strupcase(strmid(obsst,0,1))
 if ((obsst eq 'G') and (date ge 1990.0602)) or ((obsst eq 'V') and   $
       (date ge 1990.558)) then begin
    comment = 'Used new reference point (-144,-176) information, Perez (1991)'
;
; for later use - degradation corrections
;
    corr = 1.0
    cc = counts/corr
;
; compute focus dependency
;
    cc = cc * (1.0 + 0.022 * (-2.653 - fstep))
;
; compute k constant
;
    if flap eq 1 then k=10.995     ; constant used for underlap (+/- 0.078)
    if flap eq 0 then k=16.350     ; constant used for overlap  (+/- 0.063)
    
 endif else begin
    comment = 'Used former reference point (-16,-208) information, ' +   $
              'Fireman and Imhoff (1989)'
;
; compute fes counts 
;
    corr = 1.0
    if (flap eq 0) and (date gt 1981.65) then corr = 1-0.0413*(date-1981.65)
    if (flap eq 1) and (date gt 1980.6)  then corr = 1-0.0291*(date-1980.6)
    cc = counts/corr
;
; compute k constant
;
    if flap eq 1 then k=11.16        ; constant used for underlap
    if flap eq 0 then k=16.52        ; constant used for overlap
 endelse  ; reference point
;
 if (festsr) then cc = cc/4.0     ; convert for slow track
;
; compute color correction term
;
 color = (-0.271087 + (-0.06388 + 0.137764*bmv) * bmv) * bmv
;
; calculate the fes magnitude
;
 vfes = -2.5 * alog10(cc/(1-1.2e-4*cc^0.781)) + color + k
;
 if !noprint  eq 0 then begin
    print,'Original counts = ',counts,'   and color = ',bmv
    print,comment
    print,'FES magnitude = ',vfes
 endif  ; !noprint
 return
 end    ; fescalc