      FUNCTION BNRSCN(SCNTIM, PRVTIM)
      IMPLICIT NONE
C***********************************************************************
C
C   NAME- BNRSCN
C
C   LANGUAGE- VS FORTRAN  TYPE- INTEGER FUNCTION  COMPUTER- IBM SP
C
C   VERSION- 1.0   DATE-  1/15/04    PROGRAMMER- FRANK TILLEY (RAYTHEON)
C   VERSION- 1.2   DATE- 11/01/06    PROGRAMMER- FRANK TILLEY (IMSG)
C          ADDED FUNCTIONALITY TO HANDLE CASES WHERE CONVERSION FROM
C          MICROSECONDS TO MILLISECONDS IN THE PRE-PROCESSOR CAUSES
C          THE SCAN-TO-SCAN TIME DIFFERENCE TO BE SLIGHTLY LESS THAN
C          2666 MILLISECONDS.
C
C   FUNCTION- THIS FUNCTION COMPUTES THE SCAN LINE DIFFERENCE BETWEEN
C             TWO AMSU-B OR MHS 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 AMSU-B OR MHS SCAN LINE.
C   PRVTIM(2) INT     I    SCAN LINE START TIME OF PREVIOUS 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 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 BNRSCN IS RETURNED AS -999.
C                 
C               - IF THE SCAN LINE START TIMES ARE IDENTICAL, THE
C                 VALUE OF BNRSCN IS RETURNED AS -999.
C
C
C***********************************************************************
C
      INTEGER BNRSCN, SCNTIM(2), PRVTIM(2)
C
      INTEGER DYMSEC, SCANMS, DAYDIF, TMPTIM

      PARAMETER(DYMSEC=(24*60*60*1000), SCANMS=2660)
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
         BNRSCN = -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
         BNRSCN = -999
         GO TO 1000
      END IF
C
C CALCULATE THE NUMBER OF AMSU-B/MHS SCANS BETWEEN THE SCAN TIMES.
C
      BNRSCN = (TMPTIM-PRVTIM(2)) / SCANMS
C
C ALLOW FOR SMALL SCAN-TO-SCAN START TIME DELTA DIFFERENCES DUE
C TO ROUNDING FROM MICROSECONDS TO MILLISECONDS.
C 
      IF (BNRSCN.EQ.0) THEN
         IF (TMPTIM .GT. PRVTIM(2)) BNRSCN = BNRSCN + 1
      END IF
C
 1000 CONTINUE
      RETURN
      END
