C******************** START FILE UFSCDF.FOR ; GROUP UFSCLK ******************
C---------------------------------------------------------------
C  UFSCDF
C  DEFINE DIFFERENCES IN 2 SCALAR KEYWORD LISTS
C  PUT DIFFERENCES IN THIRD LIST
C
      SUBROUTINE UFSCDF(ZLIST,ZVAL,IORD,NDIM,NUM,ITYP,ISEL)
C
      CHARACTER*10 ZLIST(3,NDIM,3)
      REAL ZVAL(NDIM,3)
      INTEGER NUM(3),IORD(NDIM,3)
C
C  ZLIST-- LIST ELEMENT LABELS/KEYWORDS
C   ROW 1-- COMPARISON LIST 1
C   ROW 2-- COMPARISON LIST 2 (1 AND 2 ARE INPUT)
C   ROW 3-- DIFFERENCES LIST (OUTPUT)
C  ZVAL-- LIST ELEMENT VALUES
C  IORD-- ALPHABETIC ORDERING ON LISTS (ALREADY CALCULATED INPUT)
C  NDIM-- LIST ELEMENT ARRAY SIZES-- MAX # OF ELEMENTS
C  NUM-- NUMBER OF DEFINED ELEMENTS IN EACH LIST
C  ITYP-- COMPARISON TYPE SELECT
C   ITYP=1 - GEN LIST OF ALL KEYWORD ELEMENTS IN LIST 1 BUT NOT LIST 2
C       =2 - GEN LIST OF ALL KEYWORD ELEMENTS IN LIST 2 BUT NOT LIST 1
C       =3 - GEN LIST OF ALL ELEMENTS WITH SAME KEYWORD BUT DIFFERENT
C            LABELS IN THE TWO LISTS
C       =4 - GEN LIST OF ALL ELEMENTS WITH SAME KEYWORD BUT DIFFERENT
C            VALUES IN THE TWO LISTS
C   ISEL-- LIST SELECT; MEANINGFUL ONLY FOR ITYP=3 OR 4:
C       INSERT IN DIFFERENCES LIST ELEMENTS FROM LIST 1 IF ISEL=1,
C       INSERT ELEMENTS FROM LIST 2 IF ISEL=2
C
      NUM(3)=0
      GO TO (100,100,300,300) ITYP
C  LIST WHATS IN LIST L=ITYP, NOT IN THE OTHER LIST LC
 100  CONTINUE
      L=ITYP
      LC=3-ITYP
      IF(NUM(L).EQ.0) RETURN
      INL=NUM(L)
      DO 150 I=1,INL
C  PTR TO NEXT ALPHABETIC ENTRY IN LIST 1
      IPT=IORD(I,L)
      IF(NUM(LC).EQ.0) GO TO 140
C  LOCATE IN LIST LC
      ILOC2=
     >     IUFSLO(ZLIST(1,IPT,L),NUM(LC),ZLIST(1,1,LC),IORD(1,LC),IEQ)
      IF(IEQ.EQ.1) GO TO 150
C  ENTRY NOT PRESENT IN LIST LC
 140  CONTINUE
      NUM(3)=NUM(3)+1
      ZVAL(NUM(3),3)=ZVAL(IPT,L)
      DO 145 IJ=1,3
      ZLIST(IJ,NUM(3),3)=ZLIST(IJ,IPT,L)
 145  CONTINUE
      IORD(NUM(3),3)=NUM(3)
 150  CONTINUE
      RETURN
C  LABELS COMPARE
 300  CONTINUE
      IF(NUM(1).EQ.0) RETURN
      IF(NUM(2).EQ.0) RETURN
      L=ISEL
      LC=3-ISEL
      INL=NUM(L)
C  SCAN ENTRIES IN LIST L
      DO 350 I=1,INL
C  POINTER TO NEXT IN ALPHABETIC ORDER
      IPT=IORD(I,L)
      ILOC2=
     >     IUFSLO(ZLIST(1,IPT,L),NUM(LC),ZLIST(1,1,LC),IORD(1,LC),IEQ)
C  KEYWORD IN BOTH LISTS?
      IF(IEQ.EQ.0) GO TO 350
C  LABELS OR VALUES  AGREE?
      IPTLC=IORD(ILOC2,LC)
      IF(ITYP.EQ.3) GO TO 320
C  TEST VALUES
      IF(ZVAL(IPT,L).NE.ZVAL(IPTLC,LC)) GO TO 340
      GO TO 350
C  TEST LABELS
 320  CONTINUE
      DO 330 IJ=2,3
      IF(ZLIST(IJ,IPT,L).NE.ZLIST(IJ,IPTLC,LC)) GO TO 340
 330  CONTINUE
C  LABELS AGREE.
      GO TO 350
C  LABELS OR VALUES  DISAGREE:
 340  CONTINUE
      NUM(3)=NUM(3)+1
      ZVAL(NUM(3),3)=ZVAL(IPT,L)
      DO 345 IJ=1,3
      ZLIST(IJ,NUM(3),3)=ZLIST(IJ,IPT,L)
 345  CONTINUE
      IORD(NUM(3),3)=NUM(3)
 350  CONTINUE
      RETURN
      END
C******************** END FILE UFSCDF.FOR ; GROUP UFSCLK ******************
