      INTEGER RD1(884),RD2(884)
      INTEGER ERRS,AP,LASTAP,I1,I2,I,J
      INTEGER FX1(40),FX2(40)
      INTEGER ROW1(500),ROW2(500),BUF(500)
      INTEGER GETARG,GETNA0,FINDF0,ISATTY
      INTEGER ADDFI0,GETROW,LOADRD
      INTEGER ARG(128),OLDNA0(17),NEWNA0(17)
      INTEGER AAAAA0(19)
      INTEGER AAAAB0(22)
      INTEGER AAAAC0(22)
      INTEGER AAAAD0(27)
      DATA AAAAA0/170,243,186,160,233,238,246,225,236,233,228,160,238,22
     *5,237,229,170,238,0/
      DATA AAAAB0/170,243,186,160,230,233,229,236,228,160,238,239,244,16
     *0,230,239,245,238,228,170,238,0/
      DATA AAAAC0/170,243,186,160,228,245,240,236,233,227,225,244,229,16
     *0,230,233,229,236,228,170,238,0/
      DATA AAAAD0/170,243,186,160,227,225,238,238,239,244,160,225,228,22
     *8,160,238,229,247,160,230,233,229,236,228,170,238,0/
      IF((LOADRD(RD1,-10).EQ.-2))GOTO 10000
        CALL ERROR('Can''t access input relation.')
10000 RD2(1)=3
      RD2(2)=3-22+1
      RD2(3)=0
      ERRS=0
      AP=1
      GOTO 10003
10001 AP=AP+(1)
10003 IF((GETARG(AP,ARG,128).EQ.-1))GOTO 10002
        IF((AP.LE.40))GOTO 10004
          CALL ERROR('Too many fields in new relation.')
10004   IF((GETNA0(ARG,OLDNA0,NEWNA0).EQ.-2))GOTO 10005
          CALL PRINT(-15,AAAAA0,ARG)
          ERRS=ERRS+(1)
          GOTO 10001
10005   I1=FINDF0(RD1,OLDNA0)
        IF((I1.NE.0))GOTO 10006
          CALL PRINT(-15,AAAAB0,OLDNA0)
          ERRS=ERRS+(1)
          GOTO 10001
10006   IF((FINDF0(RD2,NEWNA0).EQ.0))GOTO 10007
          CALL PRINT(-15,AAAAC0,NEWNA0)
          ERRS=ERRS+(1)
          GOTO 10001
10007   I2=ADDFI0(RD2,RD1(I1),RD1(I1+1),NEWNA0)
        IF((I2.NE.0))GOTO 10008
          CALL PRINT(-15,AAAAD0,NEWNA0)
          ERRS=ERRS+(1)
          GOTO 10001
10008   FX1(AP)=I1
        FX2(AP)=I2
      GOTO 10001
10002 IF((AP.LE.1))GOTO 10009
        LASTAP=AP-1
        GOTO 10010
10009   CALL MOVE$(RD1,RD2,RD1(+1))
        J=1
        I=3+1
        GOTO 10013
10011   J=J+(1)
        I=I+22
10013   IF((I.GT.RD1(2)))GOTO 10012
          FX1(J)=I
          FX2(J)=I
        GOTO 10011
10012   LASTAP=J-1
10010 IF((ERRS.LE.0))GOTO 10014
        CALL SWT
10014 CALL SAVERD(RD2,-11)
      IF((ISATTY(-11).NE.1))GOTO 10015
        CALL PRINT0(RD2,-11)
10015 CONTINUE
10016 IF((GETROW(RD1,-10,ROW1).EQ.-1))GOTO 10017
        AP=1
        GOTO 10020
10018   AP=AP+(1)
10020   IF((AP.GT.LASTAP))GOTO 10019
          CALL GETDA0(RD1,FX1(AP),ROW1,BUF)
          CALL PUTDA0(RD2,FX2(AP),ROW2,BUF)
        GOTO 10018
10019   CALL PUTROW(RD2,-11,ROW2)
      GOTO 10016
10017 IF((ISATTY(-11).NE.1))GOTO 10021
        CALL PRINU0(RD2,-11)
10021 CALL SWT
      END
      INTEGER FUNCTION GETNA0(ARG,OLDNA0,NEWNA0)
      INTEGER ARG(1),OLDNA0(17),NEWNA0(17)
      INTEGER I,J
      NEWNA0(1)=0
      OLDNA0(1)=0
      IF((193.GT.ARG(1)))GOTO 10023
      IF((ARG(1).GT.218))GOTO 10023
      GOTO 10022
10023 IF((225.GT.ARG(1)))GOTO 10024
      IF((ARG(1).GT.250))GOTO 10024
      GOTO 10022
10024   GETNA0=-3
        RETURN
10022 OLDNA0(1)=ARG(1)
      I=2
      GOTO 10027
10025 I=I+(1)
10027 IF((ARG(I).EQ.0))GOTO 10026
      IF((ARG(I).EQ.189))GOTO 10026
      IF((I.GE.17))GOTO 10026
        IF((193.GT.ARG(I)))GOTO 10029
        IF((ARG(I).GT.218))GOTO 10029
        GOTO 10028
10029   IF((225.GT.ARG(I)))GOTO 10030
        IF((ARG(I).GT.250))GOTO 10030
        GOTO 10028
10030   IF((176.GT.ARG(I)))GOTO 10031
        IF((ARG(I).GT.185))GOTO 10031
        GOTO 10028
10031   IF((ARG(I).EQ.223))GOTO 10028
          OLDNA0(1)=0
          GETNA0=-3
          RETURN
10028   OLDNA0(I)=ARG(I)
      GOTO 10025
10026 OLDNA0(I)=0
      IF((ARG(I).NE.0))GOTO 10032
        CALL CTOC(OLDNA0,NEWNA0,17)
        GOTO 10033
10032   IF((ARG(I).NE.189))GOTO 10034
          I=I+(1)
          IF((193.GT.ARG(I)))GOTO 10036
          IF((ARG(I).GT.218))GOTO 10036
          GOTO 10035
10036     IF((225.GT.ARG(I)))GOTO 10037
          IF((ARG(I).GT.250))GOTO 10037
          GOTO 10035
10037       GETNA0=-3
            RETURN
10035     NEWNA0(1)=ARG(I)
          J=2
          I=I+(1)
          GOTO 10040
10038     J=J+(1)
          I=I+(1)
10040     IF((ARG(I).EQ.0))GOTO 10039
          IF((J.GE.17))GOTO 10039
            IF((193.GT.ARG(I)))GOTO 10042
            IF((ARG(I).GT.218))GOTO 10042
            GOTO 10041
10042       IF((225.GT.ARG(I)))GOTO 10043
            IF((ARG(I).GT.250))GOTO 10043
            GOTO 10041
10043       IF((176.GT.ARG(I)))GOTO 10044
            IF((ARG(I).GT.185))GOTO 10044
            GOTO 10041
10044       IF((ARG(I).EQ.223))GOTO 10041
              NEWNA0(1)=0
              GETNA0=-3
              RETURN
10041       NEWNA0(J)=ARG(I)
          GOTO 10038
10039     NEWNA0(J)=0
          IF((ARG(I).EQ.0))GOTO 10045
            GETNA0=-3
            RETURN
10045     GOTO 10046
10034     GETNA0=-3
          RETURN
10046 CONTINUE
10033 GETNA0=-2
      RETURN
      END
      INTEGER FUNCTION LOADRD(RD,FD)
      INTEGER RD(884)
      INTEGER FD
      INTEGER ISATTY,READF
      IF((ISATTY(FD).NE.1))GOTO 10047
        CALL REMARK('Sorry, a relation can''t be read from the terminal.
     *')
        LOADRD=-3
        RETURN
10047 IF((READF(RD(1),1,FD).NE.-1))GOTO 10048
        LOADRD=-3
        RETURN
10048 IF((READF(RD(2),RD(1)-1,FD).NE.-1))GOTO 10049
        CALL REMARK('relation is corrupted!!.')
        LOADRD=-3
        RETURN
10049 LOADRD=-2
      RETURN
      END
      SUBROUTINE SAVERD(RD,FD)
      INTEGER RD(884)
      INTEGER FD
      INTEGER ISATTY
      IF((ISATTY(FD).NE.1))GOTO 10050
        CALL PRINV0(RD,FD)
        GOTO 10051
10050   CALL WRITEF(RD,RD(1),FD)
10051 RETURN
      END
      SUBROUTINE PRINV0(RD,FD)
      INTEGER RD(884)
      INTEGER FD
      INTEGER I
      INTEGER TYPE(102)
      INTEGER AAAAE0(10)
      INTEGER AAAAF0(33)
      INTEGER AAAAG0(10)
      INTEGER AAAAH0
      INTEGER AAAAI0(8)
      INTEGER AAAAJ0(5)
      INTEGER AAAAK0(7)
      INTEGER AAAAL0(24)
      INTEGER AAAAM0(10)
      DATA AAAAE0/170,179,185,172,172,173,248,170,238,0/
      DATA AAAAF0/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 AAAAG0/170,179,185,172,172,173,248,170,238,0/
      DATA AAAAI0/233,238,244,229,231,229,242,0/
      DATA AAAAJ0/242,229,225,236,0/
      DATA AAAAK0/243,244,242,233,238,231,0/
      DATA AAAAL0/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 AAAAM0/170,179,185,172,172,173,248,170,238,0/
      CALL PRINT(FD,AAAAE0)
      CALL PRINT(FD,AAAAF0)
      CALL PRINT(FD,AAAAG0)
      I=3+1
      GOTO 10054
10052 I=I+22
10054 IF((I.GT.RD(2)))GOTO 10053
        AAAAH0=RD(I)
        GOTO 10055
10056     CALL CTOC(AAAAI0,TYPE,102)
        GOTO 10057
10058     CALL CTOC(AAAAJ0,TYPE,102)
        GOTO 10057
10059     CALL CTOC(AAAAK0,TYPE,102)
        GOTO 10057
10055   GOTO(10056,10058,10059),AAAAH0
10057   CALL PRINT(FD,AAAAL0,TYPE,RD(I+1),RD(I+5))
      GOTO 10052
10053 CALL PRINT(FD,AAAAM0)
      RETURN
      END
      INTEGER FUNCTION ADDFI0(RD,TYPE,LEN,NAME)
      INTEGER RD(884)
      INTEGER TYPE,LEN
      INTEGER NAME(1)
      INTEGER I
      INTEGER AAAAN0
      I=RD(2)+22
      IF((I+22-1.LE.884))GOTO 10060
        ADDFI0=0
        RETURN
10060 RD(I)=TYPE
      RD(I+4)=LENGTH(NAME)
      AAAAN0=TYPE
      GOTO 10061
10062   RD(I+1)=2
        RD(I+4)=MAX0(RD(I+4),10)
      GOTO 10063
10064   RD(I+1)=4
        RD(I+4)=MAX0(RD(I+4),15)
      GOTO 10063
10065   RD(I+1)=LEN
        RD(I+4)=MAX0(RD(I+4),LEN)
      GOTO 10063
10061 GOTO(10062,10064,10065),AAAAN0
        CALL ERROR('in add_field_to_rd: bogus type passed.')
10063 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 10066
        ADDFI0=0
        RETURN
10066 ADDFI0=I
      RETURN
      END
      INTEGER FUNCTION FINDF0(RD,NAME)
      INTEGER RD(884)
      INTEGER NAME(1)
      INTEGER I
      INTEGER EQUAL
      I=3+1
      GOTO 10069
10067 I=I+22
10069 IF((I.GT.RD(2)))GOTO 10068
        IF((EQUAL(RD(I+5),NAME).NE.1))GOTO 10070
          FINDF0=I
          RETURN
10070 GOTO 10067
10068 FINDF0=0
      RETURN
      END
      INTEGER FUNCTION COMPA0(TYPE,BUF1,BUF2)
      INTEGER TYPE
      INTEGER BUF1(500),BUF2(500)
      INTEGER R
      INTEGER COMPB0,COMPC0,COMPD0
      INTEGER AAAAO0
      INTEGER AAAAP0(34)
      DATA AAAAP0/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/
      AAAAO0=TYPE
      GOTO 10071
10072   R=COMPB0(BUF1,BUF2)
      GOTO 10073
10074   R=COMPC0(BUF1,BUF2)
      GOTO 10073
10075   R=COMPD0(BUF1,BUF2)
      GOTO 10073
10071 GOTO(10072,10074,10075),AAAAO0
        CALL PRINT(-15,AAAAP0,TYPE)
        R=2
10073 COMPA0=R
      RETURN
      END
      INTEGER FUNCTION COMPB0(I1,I2)
      INTEGER * 4 I1,I2
      IF((I1.GE.I2))GOTO 10076
        COMPB0=1
        RETURN
10076 IF((I1.LE.I2))GOTO 10077
        COMPB0=3
        RETURN
10077 COMPB0=2
      RETURN
      END
      INTEGER FUNCTION COMPC0(D1,D2)
      REAL * 8 D1,D2
      IF((D1.GE.D2))GOTO 10078
        COMPC0=1
        RETURN
10078 IF((D1.LE.D2))GOTO 10079
        COMPC0=3
        RETURN
10079 COMPC0=2
      RETURN
      END
      INTEGER FUNCTION COMPD0(S1,S2)
      INTEGER S1(1),S2(1)
      INTEGER I
      I=1
      GOTO 10082
10080 I=I+(1)
10082 IF((S1(I).NE.S2(I)))GOTO 10081
      IF((S1(I).EQ.0))GOTO 10081
      GOTO 10080
10081 IF((S1(I).NE.S2(I)))GOTO 10083
        COMPD0=2
        RETURN
10083 IF((S1(I).EQ.0))GOTO 10085
      IF((S1(I).LT.S2(I)))GOTO 10085
      GOTO 10084
10085   COMPD0=1
        RETURN
10084 COMPD0=3
      RETURN
      END
      SUBROUTINE PRINT0(RD,FD)
      INTEGER RD(884)
      INTEGER FD
      INTEGER I
      INTEGER AAAAQ0(2)
      INTEGER AAAAR0(7)
      INTEGER AAAAS0(3)
      INTEGER AAAAT0(2)
      INTEGER AAAAU0(7)
      INTEGER AAAAV0(3)
      INTEGER AAAAW0(2)
      INTEGER AAAAX0(7)
      INTEGER AAAAY0(3)
      DATA AAAAQ0/173,0/
      DATA AAAAR0/170,163,172,172,173,248,0/
      DATA AAAAS0/170,238,0/
      DATA AAAAT0/252,0/
      DATA AAAAU0/160,170,163,243,160,252,0/
      DATA AAAAV0/170,238,0/
      DATA AAAAW0/173,0/
      DATA AAAAX0/170,163,172,172,173,248,0/
      DATA AAAAY0/170,238,0/
      CALL PRINT(FD,AAAAQ0)
      I=3+1
      GOTO 10088
10086 I=I+22
10088 IF((I.GT.RD(2)))GOTO 10087
        CALL PRINT(FD,AAAAR0,RD(I+4)+3)
      GOTO 10086
10087 CALL PRINT(FD,AAAAS0)
      CALL PRINT(FD,AAAAT0)
      I=3+1
      GOTO 10091
10089 I=I+22
10091 IF((I.GT.RD(2)))GOTO 10090
        CALL PRINT(FD,AAAAU0,RD(I+4),RD(I+5))
      GOTO 10089
10090 CALL PRINT(FD,AAAAV0)
      CALL PRINT(FD,AAAAW0)
      I=3+1
      GOTO 10094
10092 I=I+22
10094 IF((I.GT.RD(2)))GOTO 10093
        CALL PRINT(FD,AAAAX0,RD(I+4)+3)
      GOTO 10092
10093 CALL PRINT(FD,AAAAY0)
      RETURN
      END
      SUBROUTINE PRINU0(RD,FD)
      INTEGER RD(884)
      INTEGER FD
      INTEGER I
      INTEGER AAAAZ0(2)
      INTEGER AAABA0(7)
      INTEGER AAABB0(3)
      DATA AAAAZ0/173,0/
      DATA AAABA0/170,163,172,172,173,248,0/
      DATA AAABB0/170,238,0/
      CALL PRINT(FD,AAAAZ0)
      I=3+1
      GOTO 10097
10095 I=I+22
10097 IF((I.GT.RD(2)))GOTO 10096
        CALL PRINT(FD,AAABA0,RD(I+4)+3)
      GOTO 10095
10096 CALL PRINT(FD,AAABB0)
      RETURN
      END
      SUBROUTINE PRINW0(RD,FD,BUF)
      INTEGER RD(884)
      INTEGER FD
      INTEGER BUF(500)
      INTEGER I
      INTEGER AAABC0(2)
      INTEGER AAABD0
      INTEGER AAABE0(7)
      INTEGER AAABF0(7)
      INTEGER AAABG0(9)
      INTEGER AAABH0(3)
      DATA AAABC0/252,0/
      DATA AAABE0/160,170,163,236,160,252,0/
      DATA AAABF0/160,170,163,228,160,252,0/
      DATA AAABG0/160,170,163,172,163,243,160,252,0/
      DATA AAABH0/170,238,0/
      CALL PRINT(FD,AAABC0)
      I=3+1
      GOTO 10100
10098 I=I+22
10100 IF((I.GT.RD(2)))GOTO 10099
        AAABD0=RD(I)
        GOTO 10101
10102     CALL PRINT(FD,AAABE0,RD(I+4),BUF(RD(I+2)))
        GOTO 10103
10104     CALL PRINT(FD,AAABF0,RD(I+4),BUF(RD(I+2)))
        GOTO 10103
10105     CALL PRINT(FD,AAABG0,RD(I+4),RD(I+1),BUF(RD(I+2)))
        GOTO 10103
10101   GOTO(10102,10104,10105),AAABD0
10103 GOTO 10098
10099 CALL PRINT(FD,AAABH0)
      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 10106
        CALL PRINW0(RD,FD,BUF)
        GOTO 10107
10106   CALL WRITEF(BUF,RD(3),FD)
10107 RETURN
      END
      SUBROUTINE GETDA0(RD,I,BUF,DEST)
      INTEGER RD(884)
      INTEGER I,BUF(1),DEST(102)
      INTEGER J,K
      INTEGER AAABI0
      AAABI0=RD(I)
      GOTO 10108
10109   J=RD(I+2)
        DEST(1)=BUF(J)
        DEST(2)=BUF(J+1)
      GOTO 10110
10111   J=RD(I+2)
        DEST(1)=BUF(J)
        DEST(2)=BUF(J+1)
        DEST(3)=BUF(J+2)
        DEST(4)=BUF(J+3)
      GOTO 10110
10112   J=RD(I+3)
        K=RD(I+1)
        GOTO 10115
10113   J=J-(1)
        K=K-(1)
10115   IF((K.LE.0))GOTO 10114
        IF((BUF(J).NE.160))GOTO 10114
        GOTO 10113
10114   DEST(K+1)=0
        GOTO 10118
10116   J=J-(1)
        K=K-(1)
10118   IF((K.LE.0))GOTO 10117
          DEST(K)=BUF(J)
        GOTO 10116
10117 GOTO 10110
10108 GOTO(10109,10111,10112),AAABI0
10110 RETURN
      END
      SUBROUTINE PUTDA0(RD,I,BUF,SRC)
      INTEGER RD(884)
      INTEGER I,BUF(1),SRC(102)
      INTEGER J,K
      INTEGER AAABJ0
      AAABJ0=RD(I)
      GOTO 10119
10120   J=RD(I+2)
        BUF(J)=SRC(1)
        BUF(J+1)=SRC(2)
      GOTO 10121
10122   J=RD(I+2)
        BUF(J)=SRC(1)
        BUF(J+1)=SRC(2)
        BUF(J+2)=SRC(3)
        BUF(J+3)=SRC(4)
      GOTO 10121
10123   J=RD(I+2)
        K=1
        GOTO 10126
10124   J=J+(1)
        K=K+(1)
10126   IF((SRC(K).EQ.0))GOTO 10125
        IF((K.GT.RD(I+1)))GOTO 10125
          BUF(J)=SRC(K)
        GOTO 10124
10125   GOTO 10129
10127   K=K+(1)
        J=J+(1)
10129   IF((K.GT.RD(I+1)))GOTO 10128
          BUF(J)=160
        GOTO 10127
10128 GOTO 10121
10119 GOTO(10120,10122,10123),AAABJ0
10121 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 10132
10130 I=I+22
10132 IF((I.GT.RD(2)))GOTO 10131
        CALL GETDA0(RD,I,ROW1,BUF1)
        CALL GETDA0(RD,I,ROW2,BUF2)
        R=COMPA0(RD(I),BUF1,BUF2)
        IF((R.EQ.2))GOTO 10133
          COMPE0=R
          RETURN
10133 GOTO 10130
10131 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 printrd                        prinv0
C printrow                       prinw0
C comparereal                    compc0
C getdata                        getda0
C addfieldtord                   addfi0
C oldname                        oldna0
C getname                        getna0