      INTEGER RD1(884),RD2(884),RD3(884),RD4(884)
      INTEGER ERRS,AP,LASTAP,I1,I2,I,J,K,L,POS2,PUT
      INTEGER MATCH1(40),MATCH2(40)
      INTEGER OUT1(40),OUT2(40)
      INTEGER ROW1(500),ROW2(500)
      INTEGER ROW3(500),ROW4(500),BUF(500)
      INTEGER BUF1(500),BUF2(500)
      INTEGER RPN(200),CBUF(500)
      INTEGER GETARG,LOADRD,GETROW,ISATTY,EVAL,PARSE,ADDFI0
      INTEGER GETNA0,FINDF0,FINDQ0,COMPA0
      INTEGER ARG(128),OLDNA0(128),NEWNA0(17)
      INTEGER * 4 M
      INTEGER * 4 MARKF
      INTEGER AAAAA0(18)
      DATA AAAAA0/230,233,229,236,228,160,238,239,244,160,230,239,245,23
     *8,228,170,238,0/
      IF((LOADRD(RD1,-10).EQ.-2))GOTO 10000
        CALL ERROR('Cannot load input relation 1.')
10000 IF((LOADRD(RD2,-12).EQ.-2))GOTO 10001
        CALL ERROR('Cannot load input relation 2.')
10001 CALL MOVE$(RD1,RD3,RD1(1))
      AP=0
      I=3+1
      GOTO 10004
10002 I=I+22
10004 IF((I.GT.RD2(2)))GOTO 10003
        J=FINDF0(RD3,RD2(I+5))
        IF((J.NE.0))GOTO 10005
          POS2=ADDFI0(RD3,RD2(I),RD2(I+1),RD2(I+5))
          IF((POS2.NE.0))GOTO 10006
            CALL ERROR('Resulting relation has too many domains.')
10006     GOTO 10007
10005     AP=AP+1
          MATCH1(AP)=J
          MATCH2(AP)=I
10007 GOTO 10002
10003 LASTAP=AP
      CALL SAVERD(RD3,-11)
      IF((ISATTY(-11).NE.1))GOTO 10008
        CALL PRINT0(RD3,-11)
10008 M=MARKF(-12)
10009 IF((GETROW(RD1,-10,ROW1).EQ.-1))GOTO 10010
        J=3+1
        I=3+1
        GOTO 10013
10011   I=I+22
10013   IF((I.GT.RD1(2)))GOTO 10012
          CALL GETDA0(RD1,I,ROW1,BUF1)
          CALL PUTDA0(RD3,J,ROW3,BUF1)
          J=J+22
        GOTO 10011
10012   CALL SEEKF(M,-12)
10014   IF((GETROW(RD2,-12,ROW2).EQ.-1))GOTO 10015
          PUT=1
          AP=1
          GOTO 10018
10016     AP=AP+(1)
10018     IF((AP.GT.LASTAP))GOTO 10017
            CALL GETDA0(RD1,MATCH1(AP),ROW1,BUF1)
            CALL GETDA0(RD2,MATCH2(AP),ROW2,BUF2)
            IF((COMPA0(RD1(MATCH1(AP)),BUF1,BUF2).EQ.2))GOTO 10019
              PUT=0
10019     GOTO 10016
10017     IF((PUT.NE.1))GOTO 10020
            I=J
            GOTO 10023
10021       I=I+22
10023       IF((I.GT.RD3(2)))GOTO 10022
              K=FINDF0(RD2,RD3(I+5))
              IF((K.NE.0))GOTO 10024
                CALL PRINT(-11,AAAAA0)
                GOTO 10025
10024           CALL GETDA0(RD2,K,ROW2,BUF2)
                CALL PUTDA0(RD3,I,ROW3,BUF2)
10025       GOTO 10021
10022       CALL PUTROW(RD3,-11,ROW3)
10020   GOTO 10014
10015 GOTO 10009
10010 IF((ISATTY(-11).NE.1))GOTO 10026
        CALL PRINU0(RD3,-11)
10026 CALL SWT
      END
      INTEGER FUNCTION GETNA0(ARG,OLDNA0,NEWNA0)
      INTEGER ARG(1),OLDNA0(128),NEWNA0(17)
      INTEGER I,J
      NEWNA0(1)=0
      OLDNA0(1)=0
      IF((193.GT.ARG(1)))GOTO 10028
      IF((ARG(1).GT.218))GOTO 10028
      GOTO 10027
10028 IF((225.GT.ARG(1)))GOTO 10029
      IF((ARG(1).GT.250))GOTO 10029
      GOTO 10027
10029   GETNA0=-3
        RETURN
10027 OLDNA0(1)=ARG(1)
      I=2
      GOTO 10032
10030 I=I+(1)
10032 IF((ARG(I).EQ.0))GOTO 10031
      IF((ARG(I).EQ.189))GOTO 10031
      IF((I.GE.128))GOTO 10031
        IF((193.GT.ARG(I)))GOTO 10034
        IF((ARG(I).GT.218))GOTO 10034
        GOTO 10033
10034   IF((225.GT.ARG(I)))GOTO 10035
        IF((ARG(I).GT.250))GOTO 10035
        GOTO 10033
10035   IF((176.GT.ARG(I)))GOTO 10036
        IF((ARG(I).GT.185))GOTO 10036
        GOTO 10033
10036   IF((ARG(I).EQ.223))GOTO 10033
        IF((ARG(I).EQ.174))GOTO 10033
          OLDNA0(1)=0
          GETNA0=-3
          RETURN
10033   OLDNA0(I)=ARG(I)
      GOTO 10030
10031 OLDNA0(I)=0
      IF((ARG(I).NE.0))GOTO 10037
        I=1
        GOTO 10040
10038   I=I+(1)
10040   IF((ARG(I).EQ.174))GOTO 10039
        IF((ARG(I).EQ.0))GOTO 10039
        IF((I.GE.17))GOTO 10039
          NEWNA0(I)=ARG(I)
        GOTO 10038
10039   NEWNA0(I)=0
        GOTO 10041
10037   IF((ARG(I).NE.189))GOTO 10042
          I=I+(1)
          IF((193.GT.ARG(I)))GOTO 10044
          IF((ARG(I).GT.218))GOTO 10044
          GOTO 10043
10044     IF((225.GT.ARG(I)))GOTO 10045
          IF((ARG(I).GT.250))GOTO 10045
          GOTO 10043
10045       GETNA0=-3
            RETURN
10043     NEWNA0(1)=ARG(I)
          J=2
          I=I+(1)
          GOTO 10048
10046     J=J+(1)
          I=I+(1)
10048     IF((ARG(I).EQ.0))GOTO 10047
          IF((J.GE.17))GOTO 10047
            IF((193.GT.ARG(I)))GOTO 10050
            IF((ARG(I).GT.218))GOTO 10050
            GOTO 10049
10050       IF((225.GT.ARG(I)))GOTO 10051
            IF((ARG(I).GT.250))GOTO 10051
            GOTO 10049
10051       IF((176.GT.ARG(I)))GOTO 10052
            IF((ARG(I).GT.185))GOTO 10052
            GOTO 10049
10052       IF((ARG(I).EQ.223))GOTO 10049
              NEWNA0(1)=0
              GETNA0=-3
              RETURN
10049       NEWNA0(J)=ARG(I)
          GOTO 10046
10047     NEWNA0(J)=0
          IF((ARG(I).EQ.0))GOTO 10053
            GETNA0=-3
            RETURN
10053     GOTO 10054
10042     GETNA0=-3
          RETURN
10054 CONTINUE
10041 GETNA0=-2
      RETURN
      END
      INTEGER FUNCTION LOADRD(RD,FD)
      INTEGER RD(884)
      INTEGER FD
      INTEGER ISATTY,READF
      IF((ISATTY(FD).NE.1))GOTO 10055
        CALL REMARK('Sorry, a relation can''t be read from the terminal.
     *')
        LOADRD=-3
        RETURN
10055 IF((READF(RD(1),1,FD).NE.-1))GOTO 10056
        LOADRD=-3
        RETURN
10056 IF((READF(RD(2),RD(1)-1,FD).NE.-1))GOTO 10057
        CALL REMARK('relation is corrupted!!.')
        LOADRD=-3
        RETURN
10057 LOADRD=-2
      RETURN
      END
      SUBROUTINE SAVERD(RD,FD)
      INTEGER RD(884)
      INTEGER FD
      INTEGER ISATTY
      IF((ISATTY(FD).NE.1))GOTO 10058
        CALL PRINV0(RD,FD)
        GOTO 10059
10058   CALL WRITEF(RD,RD(1),FD)
10059 RETURN
      END
      SUBROUTINE PRINV0(RD,FD)
      INTEGER RD(884)
      INTEGER FD
      INTEGER I
      INTEGER TYPE(102)
      INTEGER AAAAB0(10)
      INTEGER AAAAC0(33)
      INTEGER AAAAD0(10)
      INTEGER AAAAE0
      INTEGER AAAAF0(8)
      INTEGER AAAAG0(5)
      INTEGER AAAAH0(7)
      INTEGER AAAAI0(24)
      INTEGER AAAAJ0(10)
      DATA AAAAB0/170,179,185,172,172,173,248,170,238,0/
      DATA AAAAC0/252,160,244,249,240,229,160,160,160,160,252,160,236,22
     *9,238,231,244,232,160,252,160,238,225,237,229,170,177,179,248,252,
     *170,238,0/
      DATA AAAAD0/170,179,185,172,172,173,248,170,238,0/
      DATA AAAAF0/233,238,244,229,231,229,242,0/
      DATA AAAAG0/242,229,225,236,0/
      DATA AAAAH0/243,244,242,233,238,231,0/
      DATA AAAAI0/252,160,170,183,243,160,252,160,170,181,233,160,160,25
     *2,160,170,177,182,243,160,252,170,238,0/
      DATA AAAAJ0/170,179,185,172,172,173,248,170,238,0/
      CALL PRINT(FD,AAAAB0)
      CALL PRINT(FD,AAAAC0)
      CALL PRINT(FD,AAAAD0)
      I=3+1
      GOTO 10062
10060 I=I+22
10062 IF((I.GT.RD(2)))GOTO 10061
        AAAAE0=RD(I)
        GOTO 10063
10064     CALL CTOC(AAAAF0,TYPE,102)
        GOTO 10065
10066     CALL CTOC(AAAAG0,TYPE,102)
        GOTO 10065
10067     CALL CTOC(AAAAH0,TYPE,102)
        GOTO 10065
10063   GOTO(10064,10066,10067),AAAAE0
10065   CALL PRINT(FD,AAAAI0,TYPE,RD(I+1),RD(I+5))
      GOTO 10060
10061 CALL PRINT(FD,AAAAJ0)
      RETURN
      END
      INTEGER FUNCTION ADDFI0(RD,TYPE,LEN,NAME)
      INTEGER RD(884)
      INTEGER TYPE,LEN
      INTEGER NAME(1)
      INTEGER I
      INTEGER AAAAK0
      I=RD(2)+22
      IF((I+22-1.LE.884))GOTO 10068
        ADDFI0=0
        RETURN
10068 RD(I)=TYPE
      RD(I+4)=LENGTH(NAME)
      AAAAK0=TYPE
      GOTO 10069
10070   RD(I+1)=2
        RD(I+4)=MAX0(RD(I+4),10)
      GOTO 10071
10072   RD(I+1)=4
        RD(I+4)=MAX0(RD(I+4),15)
      GOTO 10071
10073   RD(I+1)=LEN
        RD(I+4)=MAX0(RD(I+4),LEN)
      GOTO 10071
10069 GOTO(10070,10072,10073),AAAAK0
        CALL ERROR('in add_field_to_rd: bogus type passed.')
10071 RD(I+2)=RD(3)+1
      RD(I+3)=RD(3)+RD(I+1)
      CALL CTOC(NAME,RD(I+5),17)
      RD(1)=RD(1)+(22)
      RD(2)=RD(2)+(22)
      RD(3)=RD(3)+(RD(I+1))
      IF((RD(3).LE.500))GOTO 10074
        ADDFI0=0
        RETURN
10074 ADDFI0=I
      RETURN
      END
      INTEGER FUNCTION FINDF0(RD,NAME)
      INTEGER RD(884)
      INTEGER NAME(1)
      INTEGER I
      INTEGER EQUAL
      I=3+1
      GOTO 10077
10075 I=I+22
10077 IF((I.GT.RD(2)))GOTO 10076
        IF((EQUAL(RD(I+5),NAME).NE.1))GOTO 10078
          FINDF0=I
          RETURN
10078 GOTO 10075
10076 FINDF0=0
      RETURN
      END
      INTEGER FUNCTION COMPA0(TYPE,BUF1,BUF2)
      INTEGER TYPE
      INTEGER BUF1(500),BUF2(500)
      INTEGER R
      INTEGER COMPB0,COMPC0,COMPD0
      INTEGER AAAAL0
      INTEGER AAAAM0(34)
      DATA AAAAM0/233,238,160,227,239,237,240,225,242,229,223,230,233,22
     *9,236,228,186,160,226,239,231,245,243,160,244,249,240,229,160,170,
     *233,170,238,0/
      AAAAL0=TYPE
      GOTO 10079
10080   R=COMPB0(BUF1,BUF2)
      GOTO 10081
10082   R=COMPC0(BUF1,BUF2)
      GOTO 10081
10083   R=COMPD0(BUF1,BUF2)
      GOTO 10081
10079 GOTO(10080,10082,10083),AAAAL0
        CALL PRINT(-15,AAAAM0,TYPE)
        R=2
10081 COMPA0=R
      RETURN
      END
      INTEGER FUNCTION COMPB0(I1,I2)
      INTEGER * 4 I1,I2
      IF((I1.GE.I2))GOTO 10084
        COMPB0=1
        RETURN
10084 IF((I1.LE.I2))GOTO 10085
        COMPB0=3
        RETURN
10085 COMPB0=2
      RETURN
      END
      INTEGER FUNCTION COMPC0(D1,D2)
      REAL * 8 D1,D2
      IF((D1.GE.D2))GOTO 10086
        COMPC0=1
        RETURN
10086 IF((D1.LE.D2))GOTO 10087
        COMPC0=3
        RETURN
10087 COMPC0=2
      RETURN
      END
      INTEGER FUNCTION COMPD0(S1,S2)
      INTEGER S1(1),S2(1)
      INTEGER I
      I=1
      GOTO 10090
10088 I=I+(1)
10090 IF((S1(I).NE.S2(I)))GOTO 10089
      IF((S1(I).EQ.0))GOTO 10089
      GOTO 10088
10089 IF((S1(I).NE.S2(I)))GOTO 10091
        COMPD0=2
        RETURN
10091 IF((S1(I).EQ.0))GOTO 10093
      IF((S1(I).LT.S2(I)))GOTO 10093
      GOTO 10092
10093   COMPD0=1
        RETURN
10092 COMPD0=3
      RETURN
      END
      SUBROUTINE PRINT0(RD,FD)
      INTEGER RD(884)
      INTEGER FD
      INTEGER I
      INTEGER AAAAN0(2)
      INTEGER AAAAO0(7)
      INTEGER AAAAP0(3)
      INTEGER AAAAQ0(2)
      INTEGER AAAAR0(7)
      INTEGER AAAAS0(3)
      INTEGER AAAAT0(2)
      INTEGER AAAAU0(7)
      INTEGER AAAAV0(3)
      DATA AAAAN0/173,0/
      DATA AAAAO0/170,163,172,172,173,248,0/
      DATA AAAAP0/170,238,0/
      DATA AAAAQ0/252,0/
      DATA AAAAR0/160,170,163,243,160,252,0/
      DATA AAAAS0/170,238,0/
      DATA AAAAT0/173,0/
      DATA AAAAU0/170,163,172,172,173,248,0/
      DATA AAAAV0/170,238,0/
      CALL PRINT(FD,AAAAN0)
      I=3+1
      GOTO 10096
10094 I=I+22
10096 IF((I.GT.RD(2)))GOTO 10095
        CALL PRINT(FD,AAAAO0,RD(I+4)+3)
      GOTO 10094
10095 CALL PRINT(FD,AAAAP0)
      CALL PRINT(FD,AAAAQ0)
      I=3+1
      GOTO 10099
10097 I=I+22
10099 IF((I.GT.RD(2)))GOTO 10098
        CALL PRINT(FD,AAAAR0,RD(I+4),RD(I+5))
      GOTO 10097
10098 CALL PRINT(FD,AAAAS0)
      CALL PRINT(FD,AAAAT0)
      I=3+1
      GOTO 10102
10100 I=I+22
10102 IF((I.GT.RD(2)))GOTO 10101
        CALL PRINT(FD,AAAAU0,RD(I+4)+3)
      GOTO 10100
10101 CALL PRINT(FD,AAAAV0)
      RETURN
      END
      SUBROUTINE PRINU0(RD,FD)
      INTEGER RD(884)
      INTEGER FD
      INTEGER I
      INTEGER AAAAW0(2)
      INTEGER AAAAX0(7)
      INTEGER AAAAY0(3)
      DATA AAAAW0/173,0/
      DATA AAAAX0/170,163,172,172,173,248,0/
      DATA AAAAY0/170,238,0/
      CALL PRINT(FD,AAAAW0)
      I=3+1
      GOTO 10105
10103 I=I+22
10105 IF((I.GT.RD(2)))GOTO 10104
        CALL PRINT(FD,AAAAX0,RD(I+4)+3)
      GOTO 10103
10104 CALL PRINT(FD,AAAAY0)
      RETURN
      END
      SUBROUTINE PRINW0(RD,FD,BUF)
      INTEGER RD(884)
      INTEGER FD
      INTEGER BUF(500)
      INTEGER I
      INTEGER AAAAZ0(2)
      INTEGER AAABA0
      INTEGER AAABB0(7)
      INTEGER AAABC0(7)
      INTEGER AAABD0(9)
      INTEGER AAABE0(3)
      DATA AAAAZ0/252,0/
      DATA AAABB0/160,170,163,236,160,252,0/
      DATA AAABC0/160,170,163,228,160,252,0/
      DATA AAABD0/160,170,163,172,163,243,160,252,0/
      DATA AAABE0/170,238,0/
      CALL PRINT(FD,AAAAZ0)
      I=3+1
      GOTO 10108
10106 I=I+22
10108 IF((I.GT.RD(2)))GOTO 10107
        AAABA0=RD(I)
        GOTO 10109
10110     CALL PRINT(FD,AAABB0,RD(I+4),BUF(RD(I+2)))
        GOTO 10111
10112     CALL PRINT(FD,AAABC0,RD(I+4),BUF(RD(I+2)))
        GOTO 10111
10113     CALL PRINT(FD,AAABD0,RD(I+4),RD(I+1),BUF(RD(I+2)))
        GOTO 10111
10109   GOTO(10110,10112,10113),AAABA0
10111 GOTO 10106
10107 CALL PRINT(FD,AAABE0)
      RETURN
      END
      INTEGER FUNCTION GETROW(RD,FD,BUF)
      INTEGER RD(884)
      INTEGER FD
      INTEGER BUF(500),I
      INTEGER READF
      I=READF(BUF,RD(3),FD)
      GETROW=I
      RETURN
      END
      SUBROUTINE PUTROW(RD,FD,BUF)
      INTEGER RD(884)
      INTEGER FD
      INTEGER BUF(500)
      INTEGER ISATTY
      IF((ISATTY(FD).NE.1))GOTO 10114
        CALL PRINW0(RD,FD,BUF)
        GOTO 10115
10114   CALL WRITEF(BUF,RD(3),FD)
10115 RETURN
      END
      SUBROUTINE GETDA0(RD,I,BUF,DEST)
      INTEGER RD(884)
      INTEGER I,BUF(1),DEST(102)
      INTEGER J,K
      INTEGER AAABF0
      AAABF0=RD(I)
      GOTO 10116
10117   J=RD(I+2)
        DEST(1)=BUF(J)
        DEST(2)=BUF(J+1)
      GOTO 10118
10119   J=RD(I+2)
        DEST(1)=BUF(J)
        DEST(2)=BUF(J+1)
        DEST(3)=BUF(J+2)
        DEST(4)=BUF(J+3)
      GOTO 10118
10120   J=RD(I+3)
        K=RD(I+1)
        GOTO 10123
10121   J=J-(1)
        K=K-(1)
10123   IF((K.LE.0))GOTO 10122
        IF((BUF(J).NE.160))GOTO 10122
        GOTO 10121
10122   DEST(K+1)=0
        GOTO 10126
10124   J=J-(1)
        K=K-(1)
10126   IF((K.LE.0))GOTO 10125
          DEST(K)=BUF(J)
        GOTO 10124
10125 GOTO 10118
10116 GOTO(10117,10119,10120),AAABF0
10118 RETURN
      END
      SUBROUTINE PUTDA0(RD,I,BUF,SRC)
      INTEGER RD(884)
      INTEGER I,BUF(1),SRC(102)
      INTEGER J,K
      INTEGER AAABG0
      AAABG0=RD(I)
      GOTO 10127
10128   J=RD(I+2)
        BUF(J)=SRC(1)
        BUF(J+1)=SRC(2)
      GOTO 10129
10130   J=RD(I+2)
        BUF(J)=SRC(1)
        BUF(J+1)=SRC(2)
        BUF(J+2)=SRC(3)
        BUF(J+3)=SRC(4)
      GOTO 10129
10131   J=RD(I+2)
        K=1
        GOTO 10134
10132   J=J+(1)
        K=K+(1)
10134   IF((SRC(K).EQ.0))GOTO 10133
        IF((K.GT.RD(I+1)))GOTO 10133
          BUF(J)=SRC(K)
        GOTO 10132
10133   GOTO 10137
10135   K=K+(1)
        J=J+(1)
10137   IF((K.GT.RD(I+1)))GOTO 10136
          BUF(J)=160
        GOTO 10135
10136 GOTO 10129
10127 GOTO(10128,10130,10131),AAABG0
10129 RETURN
      END
      INTEGER FUNCTION COMPE0(RD,ROW1,ROW2)
      INTEGER RD(884)
      INTEGER ROW1(500),ROW2(500)
      INTEGER BUF1(500),BUF2(500)
      INTEGER R,I
      INTEGER COMPA0
      I=3+1
      GOTO 10140
10138 I=I+22
10140 IF((I.GT.RD(2)))GOTO 10139
        CALL GETDA0(RD,I,ROW1,BUF1)
        CALL GETDA0(RD,I,ROW2,BUF2)
        R=COMPA0(RD(I),BUF1,BUF2)
        IF((R.EQ.2))GOTO 10141
          COMPE0=R
          RETURN
10141 GOTO 10138
10139 COMPE0=2
      RETURN
      END
C ---- Long Name Map ----
C comparefield                   compa0
C printheader                    print0
C comparerow                     compe0
C newname                        newna0
C printtrailer                   prinu0
C putdata                        putda0
C compareinteger                 compb0
C comparestring                  compd0
C findfield                      findf0
C findqualfield                  findq0
C printrd                        prinv0
C printrow                       prinw0
C comparereal                    compc0
C getdata                        getda0
C addfieldtord                   addfi0
C oldname                        oldna0
C getname                        getna0
