      REAL FUNCTION SATZEN(HEIGHT,SPOT,INSANG,INST)
      IMPLICIT NONE
C
C********************************************************************
C
C   NAME- SATZEN
C
C   LANGUAGE- FORTRAN 77     TYPE- FUNCTION        COMPUTER- AIX
C
C   VERSION- 1.0    DATE- 04/02/91   PROGRAMMER- JEFF MANNING, SMSRC
C   VERSION- 3.0    DATE- 05/10/96   PROGRAMMER- ALEX POZDNYAK, FDC  
C      FOR REHOSTING TO THE CRAY, CHANGED ALL I*4 DECLARATIONS TO
C      INTEGER AND ALL R*4 DECLARATIONS TO REAL.
C   VERSION- 3.1    DATE- 06/09/98   PROGRAMMER- LEAH WILSON, RSTX
C      ADD CHECK FOR SATELLITE HEIGHT IN KM - IT SHOULD NEVER GO
C      HIGHER THAN 880 KM OR LOWER THAN 800 KM.  PRINT KIDS MESSAGE
C      IF IT DOES, AND RETURN A SATZEN=R4SPV.  ALSO ADDED INST TO
C      IDENTIFY THE INSTRUMENT FOR WHICH SATZEN WAS CALLED.
C   VERSION- 3.2    DATE- 10/20/00   PROGRAMMER- A. ALLEGRINO, RTISS
C      RAISED THE UPPER LIMIT OF THE SATELLITE HEIGHT TO 890KM FROM
C      880KM.
C   VERSION- 3.3    DATE- 12/04/00   PROGRAMMER- A. ALLEGRINO, RTISS
C      RAISED THE UPPER LIMIT OF THE SATELLITE HEIGHT TO 895KM FROM
C      890KM.
C   VERSION- 3.4    DATE- 08/04/06   PROGRAMMER- FRANK TILLEY (IMSG)
C      RESTRICTED THE NUMBER OF WARNING MESSAGES TO FIVE PER ORBIT.
C      CHANGED CODE TO CALCULATE SATELLITE ZENITH ANGLE EVEN WHEN
C      THE SATELLITE HEIGHT IS OUT OF BOUNDS.
C
C   FUNCTION- THIS ROUTINE CALCULATES THE SATELLITE ZENITH ANGLE
C             FOR A FIELD OF VIEW.
C
C   CALLING SEQUENCE PARAMETERS-
C     VARIABLE      I/O   TYPE      DESCRIPTION
C     --------      ---   ----      -----------
C     SATZEN         O    REAL      SATELLITE ZENITH ANGLE.
C     HEIGHT         I    REAL      SATELLITE HEIGHT IN KILOMETERS.
C     SPOT           I     INT      NUMBER OF FIELD OF VIEW IN A
C                                   SCAN LINE.
C     INSANG(3)      I    REAL      CONTAINS THE INSTRUMENT ANGLE
C                                   INFORMATION IN 3 ELEMENTS.
C                                   (1) HALF THE CROSS-TRACK SCAN ANGLE
C                                   FOR THE INSTRUMENT; NEGATIVE IF
C                                   THE SCAN IS FROM LEFT TO RIGHT
C                                   ACROSS THE VECTOR OF THE SATEL-
C                                   LITE MOTION, POSITIVE IF RIGHT
C                                   TO LEFT (FROM THE CDB).
C                                   (2) STEP ANGLE FOR THE INSTRUMENT;
C                                   POSITIVE IF THE DIRECTION OF THE
C                                   SCAN IS FROM LEFT TO RIGHT ACROSS
C                                   THE VECTOR SATELLITE MOTION,
C                                   NEGATIVE IF FROM RIGHT TO LEFT.
C                                   (FROM THE CDB)
C                                   (3) ANGLE CORRECTION FOR INSTRUMENT
C                                   MISALIGNMENT (FROM CDB).
C                                   DIMENSION (3)
C     INST           I    INTEGER   1=HIRS,2=AMSU-A,3=GAC.
C
C   LOCAL PARAMTERS-
C     VARIABLE      TYPE      DEFINITION
C     --------      ----      ----------
C     NADIR         REAL      RETRIEVES THE NADIR ANGLE FROM THE
C                             FUNCTION NADANG.
C     I6TEMP        INT       INTEGER VALUE OF HEIGHT.
C     C2TEMP        CH*2      TEMPORARY BUFFER FOR KIDS.
C     C6TEMP        CH*6      TEMPORARY BUFFER FOR KIDS.
C     SUBNAM        CH*6      MAIN MODULE NAME.         
C     KMSG          CH*100    KIDS MESSAGE BUFFER.            
C     MSGCNT        INT       COUNTER FOR THE NUMBER OF WARNING
C                             MESSAGES WRITTEN OUT PER ORBIT.
C
C   FUNCTION USED- NADANG 
C
C   SUBROUTINES CALLED - KIDS
C
C   INTRINSIC FUNCTIONS USED- ASIN, SIN, ABS
C
C   EXIT STATES- NONE
C
C********************************************************************
C
      CHARACTER*2 C2TEMP
      CHARACTER*6 C6TEMP
      CHARACTER*8 SUBNAM
      CHARACTER*100 KMSG
      INTEGER SPOT,INST,I6TEMP,MSGCNT
      REAL    INSANG(3),HEIGHT,NADANG,NADIR
C
      INCLUDE 'RMPHSCON'
      INCLUDE 'SPGUNT'
      INCLUDE 'SPVAL'

      DATA MSGCNT/0/
      SAVE MSGCNT
C
C     INITIALIZE SATZEN
C
      SATZEN = R4SPV
      IF(HEIGHT.GT.895.0.OR.HEIGHT.LT.800.0) THEN
        IF (MSGCNT.GE.5) GO TO 200
        MSGCNT = MSGCNT+1
        SUBNAM='SPGDVR'
        I6TEMP = INT(HEIGHT)
        IF(INST.EQ.1) THEN
        KMSG(1:50)='*WARNING* Sat. height of        found in HIRS 1b* '
           WRITE(C6TEMP,'(I6)') I6TEMP
           KMSG(26:31) = C6TEMP
           KMSG(51:100)='for spot number   .'                          
           WRITE(C2TEMP,'(I2)') SPOT  
           KMSG(67:68) = C2TEMP
        ELSEIF(INST.EQ.2) THEN
        KMSG(1:50)='*WARNING* Sat. height of        found in AMSUA 1b*'
           WRITE(C6TEMP,'(I6)') I6TEMP
           KMSG(26:31) = C6TEMP
           KMSG(51:100)=' for spot number   .'                          
           WRITE(C2TEMP,'(I2)') SPOT  
           KMSG(68:69) = C2TEMP
        ELSEIF(INST.EQ.3) THEN
        KMSG(1:50)='*WARNING* Sat. height of        found in AVHRR 1b*'
           WRITE(C6TEMP,'(I6)') I6TEMP
           KMSG(26:31) = C6TEMP
           KMSG(51:100)=' for spot number   .'                          
           WRITE(C2TEMP,'(I2)') SPOT  
           KMSG(68:69) = C2TEMP
        ELSE
           KMSG(1:50)='*WARNING* Sat. height of        found.'
        ENDIF
        CALL KIDS(KUNIT,SUBNAM,0,KMSG,0)
        KMSG='Minimum sat. height is 800 km. Maximum sat. height is 895 km'
        CALL KIDS(KUNIT,SUBNAM,0,KMSG,0)
      ENDIF
C
  200 CONTINUE
C
C     GET THE ANGLE FROM NADIR
C
      NADIR=NADANG(INSANG(1),INSANG(2),INSANG(3),SPOT)
C
C     COMPUTE THE SATELLITE ZENITH ANGLE
C
      SATZEN=ASIN((1+(HEIGHT/EMEANR))*SIN(NADIR))
C
C     CONVERT RADIANS TO DEGREES
C
      SATZEN = ABS(SATZEN*(180/PI))
C
      RETURN
      END
