      IMPLICIT REAL*8(A-H,O-Z)

      INTEGER KA(2,10),KS(11,10)

     &      ,JBO(2,10),NKO(30),IPT(10)

      REAL*4 RB(30),RR(10)

      REAL*4 SIZE,AF,BT,GM,ED,EL,WFF(3),XFU(3,2)

      REAL*8 XXFU(3,2),XC(3,300),X1(3,300),X2(3,300)

     &      ,XOUT(3,30),BOL(30),VA(3,50)

      REAL*4 XCC(3),R

      REAL*4 X11,Y1,Z1,X22,Y2,Z2

      INTEGER IK(300),JBB(2,300),IBB(300)

      OPEN(3,FILE='generator',iostat=ISO,STATUS='OLD')

      WRITE(6,*) ISO

      IF(ISO.NE.0) STOP

      READ(5,*) NUMBER,NNC

      IF(NUMBER.EQ.0) STOP

      CALL TSPNGE(NUMBER,NNC,3)

      READ(5,*) A,B,C

      READ(5,*) CA,CB,CC

      CALL TSLATC(A,B,C,CA,CB,CC)

      READ(5,*) NA,NKA

      READ(5,*) ((KA(J,I),J=1,2),I=1,NKA)

      DO 2 I=1,NKA

      DO 21 J=1,11

      IF(J.NE.1) KS(J,I)=0

      IF(J.EQ.1) KS(J,I)=1

   21 CONTINUE

    2 CONTINUE

      DO 3 I=1,NA

    3 READ(5,*) (VA(J,I),J=1,3)

      CALL TSCRST(VA,KA,NKA,NA,KS)

      READ(5,*) NBO

      IF(NBO.GT.0) THEN

      DO 4 I=1,NBO

      READ(5,*) (JBO(J,I),J=1,2),BOL(I),RB(I)

    4 CONTINUE

      CALL TSBOGN(JBO,BOL,NBO,0)

      JF=6

      CALL TSBOVR(JF)

      END IF

      READ(5,*) (RR(I),I=1,NKA)

      READ(5,*) (IPT(I),I=1,NKA)

      READ(5,*) MA,MB,MC,KABC

      READ(5,*) NOUT

      IF(NOUT.EQ.0) GOTO 6

      DO 5 I=1,NOUT

    5 READ(5,*) (XOUT(J,I),J=1,3),NKO(I)

    6 CONTINUE

      CALL TSCSDT(MA,MB,MC,KABC,XOUT,NKO,NOUT

     &    ,XXFU,XC,IK,NNS,JBB,IBB,NBB,X1,X2,NLINE)

      READ(5,*) SIZE,AF,BT,GM,ED,EL

      RMAX=0.0

      DO 10 I=1,NKA

      IF(RMAX.LT.RR(I)) RMAX=RR(I)

   10 CONTINUE

      DO 31 I=1,3

      XFU(I,1)=XXFU(I,1)*SIZE-RMAX

      XFU(I,2)=XXFU(I,2)*SIZE+RMAX

   31 CONTINUE

      WFF(1)=XFU(1,2)-XFU(1,1)

      WFF(2)=XFU(2,2)-XFU(2,1)

      WFF(3)=XFU(3,2)-XFU(3,1)

      CALL DRFSTR(0)

C     CALL OFLCHG(30)

      CALL ORIGIN(50.0,10.0)

      CALL TPERSP(XFU,WFF,AF,BT,GM,ED,EL)

      CALL TPTRAC(1)

      CALL TPCLEA

      DO 51 I=1,NNS

      JP=0

      IF(IK(I).NE.0) JP=IPT(IK(I))

      IF(IK(I).NE.0) R=RR(IK(I))

      IF(IK(I).EQ.0) R=0.001  

      XCC(1)=XC(1,I)*SIZE

      XCC(2)=XC(2,I)*SIZE

      XCC(3)=XC(3,I)*SIZE

      CALL TPSETS(XCC,R,JP)

   51 CONTINUE

      DO 52 I=1,NBB

      R=RB(IBB(I))

      J1=JBB(1,I)

      J2=JBB(2,I)

      CALL TPSETB(J1,J2,R)

   52 CONTINUE

      DO 53 I=1,NNS

      JJ=I

      IF(IK(I).NE.0) CALL TPDRWS(JJ)

   53 CONTINUE

      DO 54 I=1,NBB

      JJ=I

      CALL TPDRWB(JJ)

   54 CONTINUE

      write(6,*) nline

      DO 55 I=1,NLINE

      X11=X1(1,I)*SIZE

      Y1=X1(2,I)*SIZE

      Z1=X1(3,I)*SIZE

      X22=X2(1,I)*SIZE

      Y2=X2(2,I)*SIZE

      Z2=X2(3,I)*SIZE

      write(6,666) x11,y1,z1,x22,y2,z2

  666 format(3f5.1,5x,3f5.1) 

      CALL TPLINE(X11,Y1,Z1,X22,Y2,Z2,191)

   55 CONTINUE

      CALL DRFEND

      STOP

      END










