      SUBROUTINE CHKDSN(DSN,CONFIG,NUMOFI,ERSTAT)
      IMPLICIT NONE
C
C********************************************************************
C
C   NAME- CHKDSN
C
C   LANGUAGE- FORTRAN 77     TYPE- SUBROUTINE      COMPUTER- CRAY    
C
C   VERSION- 1.0    DATE- 01/14/91   PROGRAMMER- JEFF MANNING (SMSRC)
C   VERSION- 2.0    DATE- 01/04/95   PROGRAMMER- ALEX POZDNYAK (SMSRC)
C     XATOV-91:  VARIABLES "BIT" AND "MOVE" REMOVED. STATEMENTS
C                'IF(BIT(I).EQ.0)...' CNANGED TO 'IF(.NOT.(BTEST(CONFIG,
C                32-I))...'. FUNCTION DESCRIPTION ADDED.
C   VERSION- 2.1    DATE- 05/22/95   PROGRAMMER- ALEX POZDNYAK (SMSRC)
C     ATOVS-118: ARGUMENT "DSN" CHANGED FROM CH*42 TO CH*80.
C   VERSION- 3.0    DATE- 04/17/96   PROGRAMMER- ALEX POZDNYAK (FDC)   
C     MODIFIED TO RUN ON THE CRAY.  REPLACED I*4 WITH INT.
C   VERSION- 3.1    DATE- 07/20/98   PROGRAMMER- LEAH WILSON (RAYTHEON)
C   VERSION- 3.2    DATE- 08/04/00   PROGRAMMER- FRANK TILLEY (RAYTHEON)
C
C   FUNCTION- THIS ROUTINE CHECKS THE DATA SET NAMES FROM THE 1B DATA
C             SET HEADERS TO SEE IF THEY MATCH. THE DATA SET NAMES
C             CONTAINS THE DATA TYPE ,THE SATELLITE ID, AND THE SOURCE
C             (SEE THE NOAA POLAR ORBITER DATA USER'S GUIDE FOR MORE
C             INFORMATION).
C   VERSION- 3.1  IGNORE THE FIRST 9 CHARACTERS OF THE DSN SINCE THEY
C                 WILL NEVER MATCH BETWEEN INSTRUMENTS (I.E. 'N1S.
C                 HIRX' DOES NOT MATCH 'N1S.AMAX' BUT THEY CAN STILL
C                 BE FROM THE SAME ORBIT).
C   VERSION- 3.2  FOR WR #100 ADDED COMMONS /INPARM/, /INSPARM/, AND
C                 /NOHIRSCF/ TO PICK UP THE NOH1BS FLAG THAT IS SET
C                 TO TRUE WHEN NO HIRS 1B* IS AVAILABLE.
C
C   CALLING SEQUENCE PARAMETERS-
C   NAME      TYPE    I/O      DESCRIPTION
C   ----      ----    ---      ----------------------------------------
C   DSN       CH*80    I       DATA SOURCE ARRAY CONTAINING AN ELEMENT
C                              FOR EACH INSTRUMENT CONFIGURATION.
C                              DIMENSION (NUMOFI).
C   CONFIG     INT     I       INSTRUMENT CONFIGURATION. EACH INSTRUMENT
C                              HAS A CORRESPONDING BIT THAT IS SET TO
C                              ONE IF THE INSTRUMENT IS AVAILABLE, SET
C                              TO ZERO IF UNAVAILABLE.
C   NUMOFI     INT     I       NUMBER OF INSTRUMENTS.
C   ERSTAT     INT     O       ERROR STATUS CODE.
C
C   LOCAL PARAMETERS-
C   NAME      TYPE      DESCRIPTION
C   ----      ----      ------------
C   I          INT      LOOP COUNTER.
C   J          INT      LOOP COUNTER.
C   START      INT      STARTING INDEX FOR THE INSTRUMENT CHECK LOOP.
C
C   SUBROUTINES CALLED- CHKDS$
C
C   FUNCTIONS USED- BTEST
C
C   EXIT STATES- NONE.
C
C********************************************************************
C
      INCLUDE  'INPARM'
      INCLUDE  'INSPARM'
      INCLUDE  'NOHIRSCF'
C
      INTEGER   NUMOFI,I,J,ERSTAT
      INTEGER   CONFIG, START
      CHARACTER*80 DSN(NUMOFI)
C
      ERSTAT=0
C
C     IF THERE IS NO HIRS 1B*, DON'T CHECK CONFIGURATION FOR THE
C     HIRS INSTRUMENT.  THE CONFIGURATION WILL STILL SHOW THE
C     HIRS AS BEING AVAILABLE.  THIS WAS DONE TO ALLOW CLOUDY,
C     NOHIRS RETRIEVALS TO BE MADE WHEN THE HIRS INSTRUMENT IS
C     NOT AVAILABLE.
C
      START = 1
      IF (NOH1BS) START = 2
      DO 40, J=START,NUMOFI
C
C     CHECK INSTRUMENT CONFIGURATION BITS TO SEE IF INSTRUMENTS
C     ARE AVAILABLE.
C
           IF(.NOT.(BTEST(CONFIG,32-J))) GO TO 40
           DO 30, I=START,NUMOFI
               IF((.NOT.(BTEST(CONFIG,32-I))).OR.(I.EQ.J)) GO TO 30
               IF(DSN(J)(10:80).NE.DSN(I)(10:80)) THEN
                    CALL CHKDS$(307,DSN,NUMOFI,ERSTAT)
                    RETURN
               END IF
  30       CONTINUE
  40  CONTINUE
C
      RETURN
      END
C*********************************************************************
      SUBROUTINE CHKDS$(MSGCOD,DATSRC,NUMOFI,ERSTAT)
C
C*********************************************************************
C   NAME- CHKDS$
C
C   LANGUAGE- VS FORTRAN   TYPE- SUBROUTINE        COMPUTER- CRAY J916
C
C   VERSION- 1.0    DATE- 04/10/91    PROGRAMMER- JEFF MANNING (SMSRC)
C   VERSION- 2.0    DATE- 01/04/95    PROGRAMMER- ALEX POZDNYAK (SMSRC)
C     XATOV-91:  VARIABLES "BIT" AND "BSHFT" REMOVED. STATEMENT
C                'IF(BIT(I).EQ.0)...' CNANGED TO 'IF(.NOT.(BTEST(CONFIG,
C                32-I))...'.
C   VERSION- 2.1    DATE- 05/22/95   PROGRAMMER- ALEX POZDNYAK (SMSRC)
C     ATOVS-118: ARGUMENT "DATSRC" CHANGED FROM CH*42 TO CH*80.
C   VERSION- 3.0    DATE- 08/04/97   PROGRAMMER- LEAH WILSON (HSTX)   
C     CONVERT FROM MMLF TO KIDS CONVENTION.
C
C   FUNCTION- THIS SUBROUTINE IS THE ERROR HANDLING ROUTINE FOR
C             ROUTINE CHKDSN.
C
C   FILES-
C   DSN OR DESCRIPTIVE TITLE  I/O  UNIT    FUNCTIONAL DESCRIPTION
C   ------------------------  ---  ----    ----------------------------
C   .../KIDS                   O   KUNIT   KRAY I/A DOCUMENTATION SYSTEM
C
C
C   CALLING SEQUENCE PARAMETERS-
C   NAME      TYPE    I/O  DESCRIPTION
C   ----      ----    ---  -----------
C   MSGCOD     INT     I   MESSAGE CODE USED TO IDENTIFY THE ERROR
C                          PATTERN.
C   DATSRC    CH*80    I   DATA SOURCE FOR EACH INSTRUMENT.
C                          DIMENSION (NUMOFI).
C   NUMOFI     INT     I   NUMBER OF INSTRUMENTS.
C   ERSTAT     INT     O   STATUS CODE IF AN ERROR OCCURS DURING I/O.
C
C
C   COMMON AREA PARAMETERS-  ERPARM, ERINFO, SPGUNT
C
C
C   LOCAL PARAMETERS-
C   NAME    TYPE   DESRIPTION
C   ----    ----   ----------
C   STAT    INT    STATUS CODE IF AN ERROR OCCURS DURING I/O.
C   KMSG   CH*100  KIDS MESSAGE BUFFER.
C   C4TEMP  CH*4   TEMPORARY FOR WRITING TO KMSG.
C
C   SUBPROGRAMS CALLED- KIDS
C
C   FUNCTIONS USED- BTEST
C
C   EXIT STATES- NONE
C
C*********************************************************************
C
      INCLUDE  'ERPARM'
      INCLUDE  'ERINFO'
      INCLUDE  'SPGUNT'
C
      INTEGER       MSGCOD,ERSTAT,NUMOFI
      CHARACTER*4   C4TEMP
      CHARACTER*80  DATSRC(NUMOFI)
      CHARACTER*100 KMSG
C
      INTEGER      STAT, I
C
C  SET ERINFO:SUBNAM TO MAIN MODULE NAME.  KIDS SETS SUBROUTINE NAME.
C
      SUBNAM = 'SPGDVR'
C
C  INITIALIZE VARIABLES.
C
      ERSTAT=0
      STAT=0
      I=0
C
C  CHECK FOR VALID MSGCOD VALUE.
C
      IF(MSGCOD.EQ.307) THEN
        KMSG='* Data sources do not match * '
        CALL KIDS(KUNIT,SUBNAM,0,KMSG,0)
        DO 20, I=1,NUMOFI
           IF(.NOT.(BTEST(CONFIG,32-I))) GO TO 20
           KMSG='  INSTR:      DSN: '
           WRITE(C4TEMP,'(I4)') I
           KMSG(10:13) = C4TEMP
           KMSG(20:99)=DATSRC(I)
           CALL KIDS(KUNIT,SUBNAM,0,KMSG,0)
   20   CONTINUE
      ELSE
C
C NOT A VALID MSGCOD
C
        STAT=0
        KMSG = 'Invalid message code      '
        WRITE(C4TEMP,'(I4)') MSGCOD
        KMSG(22:25) = C4TEMP
        CALL KIDS(KUNIT,SUBNAM,0,KMSG,0)
      ENDIF
      RETURN
      END

