       PROGRAM KABEL
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CC     THIS PROGRAM COMPUTES THE POSITIONS OF THE PHASE            CC
CC     CABLES FOR THE POSSIBLE PHASE ANGLES.                       CC
CC     THE PHASE ANGELS ARE NUMBERED FROM N=1 TO N=17 WHERE        CC
CC     1 MEANS 1.3DEG. AND 17 IS 21.3DEG.                          CC
CC     POSITIVE VALUES OF N MEANS WEST OF BROADSIDE.               CC
CC     THE ONLY PARAMETERS GIVEN BY THE USER OF THIS PROGRAM       CC
CC     ARE OLD N AND NEW N.                                        CC
CC     TABLES GIVING THE SEQUENCE OF PHASE CABLES FOR THE          CC
CC     WANTED BEAM STEERING ANGLE ARE THEN PRINTED BY THE EP-V     CC
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
       DIMENSION J(128,2),KTN(128,2),K(128,2),KTO(128,2),IN(128,2)
       DIMENSION IO(128,2)

       DO 561 K1=1,128
          DO 562 K2=1,2
             J(K1,K2)=0
             KTN(K1,K2)=0
             K(K1,K2)=0
             KTO(K1,K2)=0
             IN(K1,K2)=0
             IO(K1,K2)=0
 562      CONTINUE
 561   CONTINUE
C
C       OPEN(5,FILE='VKABEL:OUT',ACCESS='W')
       OPEN(1,FILE='VKABEL:OUT')
       WRITE(6,*)'GIVE OLD AND NEW PHASE ANGLE NUMBER'
       WRITE(6,*)'POSITIVE N MEANS WEST OF BROADSIDE'
       WRITE(6,*)'THE CABLE NOS. FOR EACH DIPOLE ARE PRINTED ON EPSON-V'
       WRITE(6,*)
C       OUTPUT(1)
       WRITE(6,*)'$OLD N:'
       READ(5,*)NO
       WRITE(6,*)
C
       WRITE(6,*)'$NEW N:'
       READ(5,*)NN
       WRITE(6,*)
C
       CALL CABLE(NN,KTN,IN)
       CALL CABLE(NO,KTO,IO)
C
       NC=67
       X=NN/(NC*0.7)
       THETA=ATAN(X/SQRT(1.-X*X))/0.01745329252
C
       DO FOR MIN=1,65,64
           MAX=MIN+63
           DO FOR JN=MIN,MAX
           DO FOR KN=1,2
                 DO FOR JO=MIN,MAX
                     DO FOR KO=1,2
                         IF(KTN(JN,KN).EQ.KTO(JO,KO).AND.IN(JN,KN)
     *                      .EQ.IO(JO,KO))THEN
                             J(JN,KN)=JO
                             K(JN,KN)=KO
                         ENDIF
                     ENDDO
                 ENDDO
           ENDDO
           ENDDO
       ENDDO
C
C   PRINT ANSWER
C
       CALL HEADING(NO,NN,THETA)
C
       DO 200 JJ=1,4
       WRITE(1,1)NN,THETA
 1     FORMAT(8X,'SEQUENSE OF PHASE CABLES FOR ',
     B          'BEAM ANGLE NO. N=',I3,'  THETA = ',F6.1,' DEG.',/,/)
C
C
C       OUTPUT(5)
       WRITE(1, *)
       WRITE(1,334)
334    FORMAT(8X,'HORIZONTAL POLARIZATION',15X,'VERTICAL POLARIZATION')
C       OUTPUT(5)
       WRITE(1, *)
       WRITE(1,'(33X,''DIPOLE NO.'',28X,''DIPOLE NO.'')')
       WRITE(1,333)NO,NO
333    FORMAT(8X,'DIPOLE NO.',3X,'CABLE NO.   FOR N=',I3,4X,
     1             'DIPOLE NO.',3X,'CABLE NO.   FOR N=',I3,/,/)
       L1=(JJ-1)*32+1
       L2=L1+31
       DO 100 L=L1,L2
       WRITE(1,101)L,KTN(L,2),IN(L,2),J(L,2),L,KTN(L,1),IN(L,1),J(L,1)
 101   FORMAT(7X,I4,' HOR ',4X,I3,' - ',I3,6X,I3,8X,I3,' VER',5X
     *         ,I3,' - ',I3,6X,I3)
 100   CONTINUE
       WRITE(1,99)
 99    FORMAT('1')
 200   CONTINUE
       CLOSE(1)
       END
        SUBROUTINE CABLE(N,KT,I)
       DIMENSION KT(128,2),I(128,2)
C
       NC=67
       X=N/(NC*0.7)
       THETA=ATAN(X/SQRT(1.-X*X))/0.01745329252
C
C      FOR DIPOLE NO. J FIND CABLE TYPE KT(J)
C        IF(N.EQ.0.OR.N.EQ.(2*(N/2)))THEN
       DO 11 KP=1,2
       DO 10 K=8,128,8
       KT(K-1,KP)=90
       KT(K-3,KP)=90
       KT(K-4,KP)=90
       KT(K-6,KP)=90
       KT(K,KP)=0
       KT(K-2,KP)=0
       KT(K-5,KP)=0
 10    KT(K-7,KP)=0
 11    CONTINUE
C      ELSE
C      DO 13 KP=1,2
C       DO 12 K=8,128,8
C       KT(K-1,KP)=0
C       KT(K-3,KP)=0
C       KT(K-4,KP)=0
C       KT(K-6,KP)=0
C       KT(K,KP)=90
C       KT(K-2,KP)=90
C       KT(K-5,KP)=90
C 12    KT(K-7,KP)=90
C 13  CONTINUE
C
C       ENDIF
C
C
C      FOR DIPOLE NO J FIND CABLE NO I(J)
C
       N=-N
       DO 20 J=1,128
       J1=J-1
       IF(N.GE.0)THEN
         I(J,1)=N*J1-NC*(N*J1/NC)
         I(J,2)=N*J1+1-NC*((N*J1+1)/NC)
       ELSE
         I(J,1)=-N*(134-J1)-NC*((-N*(134-J1))/NC)
         I(J,2)=-N*(134-J1)+1-NC*((-N*(134-J1)+1)/NC)
       ENDIF
 20    CONTINUE
       N=-N; N1=N
       GOTO 300

C
C  IF CABLE IS USED BEFORE IN ONE ANTENNA HALF, FIND A NEW CABLE
C
       DO FOR J=2,64
               DO FOR M=1,2
                   N=2/M
                   IF(I(J,M).EQ.I(1,N).AND.KT(J,M).EQ.KT(1,N))THEN
                       JS=2*(J/2)-1
                       DO FOR K=JS,64
                           KT(K,M)=90-KT(K,M)
                       ENDDO
                   ENDIF
               ENDDO
       ENDDO
C
       DO FOR J=66,128
               DO FOR M=1,2
                   N=2/M
                   IF(I(J,M).EQ.I(65,N).AND.KT(J,M).EQ.KT(65,N))THEN
                       JS=2*(J/2)-1
                       DO FOR K=JS,128
                           KT(K,M)=90-KT(K,M)
                       ENDDO
                   ENDIF
               ENDDO
       ENDDO
C
C   PRINT ANSWER
C
       N=N1
       GOTO 300
       DO 200 JJ=1,4
       WRITE(1,1)N1
 1     FORMAT(10X,'SEQUENCE OF PHASE CABLES FOR ',
     B          'BEAM ANGLE NO. N=',I3,/)
C
       WRITE(1,2)N1,THETA
 2     FORMAT(10X,'BEAM ANGLE AT 224 MHZ IS THETA(',
     A        I3,') = ',F5.1,' DEG.',/,
     A        10X,'POS.SIGN MEANS WEST OF BROADSIDE',/)
C
         WRITE(1,*)'                           CABLE NO.'
         WRITE(1,*)
         WRITE(1,*)'         DIPOLE NO.   HOR. POL.   VER. POL.'
         WRITE(1,*)
       L1=(JJ-1)*32+1
       L2=L1+31
       DO 100 L=L1,L2
       WRITE(1,101)L,KT(L,2),I(L,2),KT(L,1),I(L,1)
 101   FORMAT(11X,I4,7X,I3,' - ',I3,3X,I3,' - ',I3)
 100   CONTINUE
       WRITE(1,99)
 99    FORMAT('1')
 200   CONTINUE
300     CONTINUE
        RETURN
        END
       SUBROUTINE HEADING(NO,NN,THETA)
C
       INTEGER NO,NN
       REAL THETA
C
       WRITE(1,100)
       WRITE(1,200)
       WRITE(1,*)'        # PHASE STEERING OF THE EISCAT VHF '
     *           ,'ANTENNA                            #'
       WRITE(1,200)
       WRITE(1,300)NO
       WRITE(1,200)
       WRITE(1,400)NN
       WRITE(1,200)
       WRITE(1,500)NN,THETA
       WRITE(1,200)
       WRITE(1,100)
       WRITE(1,'(/,/,/)')
       WRITE(1,*)'          POSITIVE N AND THETA MEANS WEST OF '
     *           ,'BROADSIDE.'
       WRITE(1,*)'          THE TABLES GIVE THE SEQUENCE OF PHASE '
     *         ,'CABLES CORRESPONDING TO THE '
       WRITE(1,*)'          WANTED BEAM STEERING ANGLE.'
       WRITE(1,*)'          THE PREVIOUS POSITION OF PHASE CABLES,'
     *           ,' I.E. FOR N=OLD N, ARE GIVEN'
       WRITE(1,*)'          AS DIPOLE NO. FOR N = OLD N.'
       WRITE(1,*)'          IF DIPOLE NO. FOR N=OLD N EQUALS ZERO '
     *           ,'THEN THE CABLE IS HANGING ON'
       WRITE(1,*)'          THE WALL.'
       WRITE (1,'(1H1)')
C
100    FORMAT(9X,36('# '))
200    FORMAT(9X,'#',T80,'#')
300    FORMAT(9X,'#  FROM BEAM ANGLE NO. N=',I3,'    (OLD N)',31X,
     *         '#')
400    FORMAT(9X,'#  TO BEAM ANGLE NO.   N=',I3,'    (NEW N)',31X,
     *         '#')
500    FORMAT(9X,'#  NEW BEAM ANGLE IS THETA(',I3,') = ',F6.1,
     *          ' DEG.',25X,'#')
       RETURN
       END


