C 1-10-91 SD  Remove prompting from CONEDT and JOINED
C 1-10-91 SD  Removed LLINOL and LLINOR from DOJOIN
C 20-Aug-92 SD Added new IOK argument to CXEDIT and JXEDIT call
C
      SUBROUTINE CONEDT(KBIN,KBOUT,
     +GELNOS,GELSTR,GELEND,
     +MAXDB,GELNO,LINNO,MAXLIN,RELPG,LNGTHG,LNBR,RNBR,
     +IDBSIZ,NGELS,NCONTS,GEL,GEL2,MAXGEL,LINCON,PERCD,IDM,
     +IHELPS,IHELPE,HELPF,IDEVH,IDEV,IDEV1,IDEV2,IDEV3,
     +IDEVT,IDEVC,LINLEN,FILNAM,LLINO,IOK,IERR,TEMP1)
C   AUTHOR: SIMON DEAR
      INTEGER RELPG(MAXDB),LNGTHG(MAXDB),LNBR(MAXDB),RNBR(MAXDB)
      CHARACTER GEL(MAXGEL),GEL2(MAXGEL)
      CHARACTER FILNAM*(*),HELPF*(*)
      INTEGER GELNOS(MAXDB),GELSTR(MAXDB),GELEND(MAXDB)
      INTEGER GELNO(MAXLIN,2),LINNO(MAXLIN,2)
      CALL SHOWFU(KBOUT,'Contig editor')
C      WRITE(KBOUT,*)'Identify contig to edit'
      CALL GETLN2(RELPG,LNGTHG,LNBR,RNBR,NGELS,NCONTS,LINCON,
     +LLINO,IGELNO,IOK,IDBSIZ,KBIN,KBOUT,IDEV3,
     +IHELPS,IHELPE,HELPF,IDEVH)
      IF(IOK.NE.0) RETURN
      CALL CXEDIT(IDEV1,IDEV2,IDEV3,IDEVT,IDEVC,
     +RELPG,LNGTHG,LNBR,RNBR,MAXGEL,
     +IDBSIZ,LINCON,LLINO,IGELNO,1,PERCD,IDM,0,IOK)
      CALL DBCHEK(RELPG,LNGTHG,LNBR,RNBR,NGELS,NCONTS,IDBSIZ,
     +TEMP1,IERR,KBOUT)
      END
      SUBROUTINE JOINED(KBIN,KBOUT,
     +GELNOS,GELSTR,GELEND,
     +MAXDB,GELNO,LINNO,MAXLIN,RELPG,LNGTHG,LNBR,RNBR,
     +IDBSIZ,NGELS,NCONTS,GEL,GEL2,MAXGEL,LINCON,PERCD,IDM,
     +IHELPS,IHELPE,HELPF,IDEVH,IDEV,IDEV1,IDEV2,IDEV3,
     +IDEVT,IDEVC,LINLEN,FILNAM,LLINO,IOK,IERR,TEMP1)
C   AUTHOR: SIMON DEAR
      INTEGER RELPG(MAXDB),LNGTHG(MAXDB),LNBR(MAXDB),RNBR(MAXDB)
      CHARACTER GEL(MAXGEL),GEL2(MAXGEL)
      CHARACTER FILNAM*(*),HELPF*(*)
      INTEGER GELNOS(MAXDB),GELSTR(MAXDB),GELEND(MAXDB)
      INTEGER GELNO(MAXLIN,2),LINNO(MAXLIN,2)
C   JOIN
      CALL SHOWFU(KBOUT,'Join editor')
C     JOIN
      WRITE(KBOUT,1006)
1006  FORMAT(' Which contigs do you want to join ?')
C      WRITE(KBOUT,1017)
C1017  FORMAT( ' Left contig')
      LLINOL = 0
      LLINOR = 0
      CALL GETLN2(RELPG,LNGTHG,LNBR,RNBR,NGELS,NCONTS,LNCONL,
     +LLINOL,IGELL,IOK,IDBSIZ,KBIN,KBOUT,IDEV3,
     +IHELPS,IHELPE,HELPF,IDEVH)
      IF(IOK.EQ.0)THEN
C        WRITE(KBOUT,1018)
C1018    FORMAT( ' Right contig')
        CALL GETLN2(RELPG,LNGTHG,LNBR,RNBR,NGELS,NCONTS,LNCONR,
     +  LLINOR,IGELR,IOK,IDBSIZ,KBIN,KBOUT,IDEV3,
     +  IHELPS,IHELPE,HELPF,IDEVH)
        IF(IOK.EQ.0)THEN
C         CHECK TO SEE IF MAKING A CIRCLE!
          IF(LLINOL.EQ.LLINOR)THEN
            WRITE(KBOUT,*)' Making circles is not allowed!'
            GO TO 200
          END IF
          CALL JXEDIT(IDEV1,IDEV2,IDEV3,IDEVT,IDEVC,
     +    RELPG,LNGTHG,LNBR,RNBR,MAXGEL,
     +    IDBSIZ,LNCONL,LLINOL,LNCONR,LLINOR,
     +    IGELL,1,IGELR,1,PERCD,NGELS,NCONTS,IDM,0,IOK)
          CALL DBCHEK(RELPG,LNGTHG,LNBR,RNBR,NGELS,NCONTS,IDBSIZ,
     +    TEMP1,IERR,KBOUT)
        END IF
      END IF
200   CONTINUE
      END
      SUBROUTINE DOJOIN(RELPG,LNGTHG,LNBR,RNBR,NGELS,NCONTS,
     +LNCONL,LNCONR,
     +IDBSIZ,IDEVR,IDEVW,
     +RELX)
C   AUTHOR: RODGER STADEN
C   TAKEN FROM: JOIN
      INTEGER LLINOL,LLINOR
      INTEGER RELPG(IDBSIZ)
      INTEGER X,RELX
      INTEGER LNGTHG(IDBSIZ),RNBR(IDBSIZ),LNBR(IDBSIZ)
C       SET UP LLINOL, LLINOR
        LLINOL = LNBR(LNCONL)
        LLINOR = LNBR(LNCONR)
C       COMPLETE JOIN
C       ADJUST ALL RELATIVE POSITIONS IN RIGHT CONTIG
        N=LLINOR
        RELPG(N)=RELX
50      CONTINUE
        IF(RNBR(N).EQ.0)GO TO 60
        N=RNBR(N)
        RELPG(N)=RELPG(N)+RELX-1
        GO TO 50
60      CONTINUE
C
C       FIX UP NEW GEL LINE FOR OLD LEFT OF RIGHT CONTIG
        LNBR(LLINOR)=RNBR(LNCONL)
C       FIX UP RIGHT GEL OF LEFT CONTIG
        N=RNBR(LNCONL)
        RNBR(N)=LLINOR
        CALL MERGE(RELPG,LNGTHG,LNBR,RNBR,LNCONL,IDBSIZ)
C       MERGE DOES NOT WRITE TO DISK
        N=LNBR(LNCONL)
65      CONTINUE
      CALL WRITER(IDEVR,N,RELPG(N),LNGTHG(N),
     +LNBR(N),RNBR(N))
        N=RNBR(N)
        IF(N.NE.0)GO TO 65
C       CONTIG LINES
        X=RELPG(LNCONR)+RELX-1
        IF(X.GT.RELPG(LNCONL))RELPG(LNCONL)=X
      CALL WRITER(IDEVR,LNCONL,RELPG(LNCONL),LNGTHG(LNCONL),
     +LNBR(LNCONL),RNBR(LNCONL))
C       NOW MOVE ALL DATA DOWN TO DELETE OLD RIGHT END
        N=IDBSIZ-NCONTS
        M=LNCONR-N
        IF(M.EQ.0)GO TO 80
        K=LNCONR
        J=LNCONR-1
        DO 70 I=1,M
          RELPG(K)=RELPG(J)
          LNGTHG(K)=LNGTHG(J)
          LNBR(K)=LNBR(J)
          RNBR(K)=RNBR(J)
      CALL WRITER(IDEVR,K,RELPG(K),LNGTHG(K),
     +LNBR(K),RNBR(K))
          K=K-1
          J=J-1
70      CONTINUE
80      CONTINUE
        NCONTS=NCONTS-1
      CALL WRITER(IDEVR,IDBSIZ,NGELS,NCONTS,NGELS,NCONTS)
        RETURN
      END
