      FUNCTION HNRSCN(SCNTIM, PRVTIM)
      IMPLICIT NONE
C***********************************************************************
C
C   NAME- HNRSCN
C
C   LANGUAGE- FORTRAN     TYPE- INTEGER FUNCTION  COMPUTER- AIX
C
C   VERSION- 1.0   DATE- 09/15/03   PROGRAMMER- FRANK TILLEY (RAYTHEON)
C   VERSION- 1.1   DATE- 11/13/06   PROGRAMMER- FRANK TILLEY (IMSG)
C      UNDER WR #300 THE VALUE OF 'SCANMS' USED CALCULATE THE SCAN
C      LINE DIFFERENCE FOR SUCCESSIVE SCAN LINE TIMES WAS CHANGED
C      FROM 6400 MILLISECONDS TO 6300 MILLISECONDS TO ACCOMMODATE
C      ROUNDING FROM MICROSECONDS TO MILLISECONDS IN METOP-2
C      SATELLITE DATA.
C
C   FUNCTION- THIS FUNCTION COMPUTES THE SCAN LINE DIFFERENCE BETWEEN
C             TWO SCAN LINE START TIMES.
C
C   CALLING SEQUENCE PARAMETERS-
C   NAME      TYPE   I/O   DESCRIPTION
C   ----      ----   ---   -----------
C   SCNTIM(2) INT     I    SCAN LINE START TIME (CENTURY DAY, MILLISECOND
C                          OF DAY) OF CURRENT HIRS SCAN LINE.
C   PRVTIM(2) INT     I    SCAN LINE START TIME OF PREVIOUS HIRS SCAN LINE. 
C
C   COMMON AREA PARAMETERS- NONE
C
C   LOCAL PARAMETERS-
C   NAME    TYPE   DESCRIPTION
C   ----    ----   -----------
C   DAYDIF  INT    DIFFERENCE IN CENTURY DAYS.
C   DYMSEC  INT    NUMBER OF MILLISECONDS IN A DAY.
C   SCANMS  INT    NUMBER OF MILLISECONDS BETWEEN HIRS SCAN LINES.
C   TMPTIM  INT    CURRENT SCAN LINE TIME IN MILLISECONDS, ADJUSTED IF
C                  NECESSARY FOR DIFFERENCES IN CENTURY DAY.
C
C   SUBROUTINES CALLED- NONE
C
C   FUNCTIONS USED- NONE
C
C   EXIT STATES - IF THE DIFFERENCE IN CENTURY DAYS IS NEGATIVE OR
C                 EXCEEDS 1, THE VALUE OF HNRSCN IS RETURNED AS -999.
C
C               - IF THE SCAN LINE START TIMES ARE IDENTICAL, THE VALUE
C                 OF HNRSCN IS RETURNED AS -999.
C
C***********************************************************************
C
      INTEGER HNRSCN, SCNTIM(2), PRVTIM(2)
C
      INTEGER DYMSEC, SCANMS, DAYDIF, TMPTIM

      PARAMETER(DYMSEC=(24*60*60*1000), SCANMS=6300)
C
C CHECK TO SEE IF CENTURY DAYS HAVE CHANGED BETWEEN SCANS.
C
      DAYDIF = SCNTIM(1) - PRVTIM(1)
C     
C IF THE DIFFERENCE IS NEGATIVE OR EXCEEDS 1, RETURN A VALUE OF -999.
C
      IF (DAYDIF.LT.0.OR.DAYDIF.GT.1) THEN
         HNRSCN = -999
         GO TO 1000
      END IF
C
C MAKE ANY NECESSARY ADJUSTMENTS TO THE CURRENT LINE START TIME IF
C THE PREVIOUS SCAN TIME IS FROM THE PREVIOUS DAY.
C
      IF (DAYDIF.EQ.1) THEN
         TMPTIM = SCNTIM(2) + DYMSEC
      ELSE
         TMPTIM = SCNTIM(2)
      END IF
C
C IF THE SCAN LINE START TIMES ARE IDENTICAL, RETURN A VALUE OF -999.
C
      IF (TMPTIM .EQ. PRVTIM(2)) THEN
         HNRSCN = -999
         GO TO 1000
      END IF
C
C CALCULATE THE NUMBER OF HIRS SCANS BETWEEN THE SCAN TIMES.
C
      HNRSCN = (TMPTIM-PRVTIM(2)) / SCANMS
C
C IF THE CALCULATION RETURNS A VALUE OF ZERO, INCREMENT THE SCAN
C LINE COUNTER BY 1 IF THE TIME OF THE CURRENT SCAN LINE IS GREATER
C THAN THE TIME OF THE PREVIOUS SCAN LINE.
C
      IF (HNRSCN.EQ.0) THEN
         IF (TMPTIM .GT. PRVTIM(2)) HNRSCN = HNRSCN + 1
      END IF
C
 1000 CONTINUE
      RETURN
      END
