*     LABEL
C*SXS*
C     PROGRAM TO PRODUCE STATE-BY-STATE SIMULATION RESULTS
C
C
C     FIRST TWO DATA CARDS CONTAIN TITLE, 12A6/12A6.
C     THIRD DATA CARD CONTAINS KAPPA1,KAPPA2,INPUT1,INPUT2,NJOB, 5I10.
C          KAPPA1 AND KAPPA2 CONTROL SUBROUTINE VOTCOR.
C          IF INPUT1 IS LESS THAN, EQUAL, OR GREATER THAN 1, THE TPRIMES
C             ARE READ IN ON CARDS, INPUT TAPE 9, OR TAPE 9,
C             RESPECTIVELY, ACCORDING TO VARIABLE FORMAT FORMT1.
C          IF INPUT2 IS LESS THAN, EQUAL, OR GREATER THAN 1, THE KENNEDY
C             AND NIXON VOTES FOR EACH CELL ARE READ IN ON CARDS, INPUT
C             TAPE 10, OR TAPE 10, RESPECTIVELY, ACCORDING TO FORMT2.
C          THE PROGRAM READS IN DATA, COMPUTES AND WRITES OUTPUT FOR
C             NJOB SETS OF KENNEDY, NIXON VOTES. IF NJOB IS LESS THAN 1,
C             IT IS SET EQUAL TO 1.
C     FOURTH DATA CARD CONTAINS THE VARIABLE FORMAT FORMT1, 12A6.
C     FIFTH DATA CARD CONTAINS THE VARIABLE FORMAT FORMT2, 12A6.
C     NEXT FOUR DATA CARDS CONTAIN VKACT FOR THE 48 STATES, 12F6.5.
C     NEXT FOUR DATA CARDS CONTAIN WEIGHTS FOR 48 STATES, 12F6.5.
C     IF INPUT1 IS LESS THAN 1, DECK OF TPRIMES FOLLOWS, FORMT1.
C     IF INPUT2 IS LESS THAN 1, NJOB DECKS OF KENNEDY, NIXON VOTES FOR
C          EACH CELL FOLLOW, FORMT2.
C
      DIMENSION TITLE(24),VKACT(48),WEIGHT(48),LCOUNT(5,10,10)
     1,VK(48,4),VN(48,4),SUM(48,4),II(1628),JJ(1628),KK(1628),MM(1628),
     2TPRIME(1628,3),III(480),JJJ(480),KKK(480),LLL(480),VOTEK(480),
     3VOTEN(480),XK1(5,10,10),XN1(5,10,10),XK2(5,10,10),XN2(5,10,10),
     4XK3(5,10,10),XN3(5,10,10),VKNORM(48,4),VNNORM(48,4),VOTE(48)
     5,MCOUNT(48),FORMT1(12),FORMT2(12)
      DIMENSION NAME(48)
C
C     READ PARAMETER CARDS AND PRINT TITLE
C
      READ 200, (TITLE(I),I=1,24)
      PRINT 300, (TITLE(I),I=1,24)
      READ 201, KAPPA1,KAPPA2,INPUT1,INPUT2,NJOB,(FORMT1(IQ),IQ=1,12),
     1(FORMT2(IQ),IQ=1,12),(VKACT(IQ),IQ=1,48),(WEIGHT(IQ),IQ=1,48)
      READ 200,NAME
      IS = 1
      IF (NJOB) 1,5,5
    1 NJOB = 1
C
C     INITIALIZE SUMS AND COUNTERS
C
      PRINT 311
    5 DO 6 I=1,5
      DO 6 J=1,10
      DO 6 K=1,10
    6 LCOUNT(I,J,K) = -111
      DO 7 M=1,48
      MCOUNT(M) = 0
      DO 7 L=1,4
      VK(M,L) = 0.0
      VN(M,L) = 0.0
    7 SUM(M,L) = 0.0
C
C     READ IN T-PRIMES FOR ALL CELLS
C
      IF (IS-1) 9,9,20
    9 IF (INPUT1-1) 10,12,14
   10 READ FORMT1,(II(I),JJ(I),KK(I),MM(I),(TPRIME(I,L),L=1,3),I=1,1628)
      GO TO 20
   12 READ INPUT TAPE 9, FORMT1, (II(I),JJ(I),KK(I),MM(I),(TPRIME(I,L),
     1L=1,3),I=1,1628)
      GO TO 20
   14 READ TAPE 9, (II(I),JJ(I),KK(I),MM(I),(TPRIME(I,L),L=1,3)I=1,1628)

C
C     READ IN AND INDEX KENNEDY AND NIXON VOTES
C
   20 IF (INPUT2-1) 21,22,23
   21 READ FORMT2,CSHIFT,(III(I),JJJ(I),KKK(I),LLL(I),VOTEK(I),VOTEN(I),
     1I=1,480)
      GO TO 24
   22 READ INPUT TAPE 10, FORMT2, CSHIFT,(III(I),JJJ(I),KKK(I),LLL(I),
     1VOTEK(I),VOTEN(I),I=1,480)
      GO TO 24
   23 READ TAPE 10, CSHIFT,(III(I),JJJ(I),KKK(I),LLL(I),VOTEK(I),
     1VOTEN(I),I=1,480)
   24 DO 25 IV=1,480
      I = III(IV) + 1
      J = JJJ(IV) + 1
      K = KKK(IV) + 1
      L = LLL(IV)
      GO TO (241,242,243),L
  241 XK1(I,J,K) = VOTEK(IV)
      XN1(I,J,K) = VOTEN(IV)
      LCOUNT(I,J,K) = LCOUNT(I,J,K) + 100
      GO TO 25
  242 XK2(I,J,K) = VOTEK(IV)
      XN2(I,J,K) = VOTEN(IV)
      LCOUNT(I,J,K) = LCOUNT(I,J,K) + 10
      GO TO 25
  243 XK3(I,J,K) = VOTEK(IV)
      XN3(I,J,K) = VOTEN(IV)
      LCOUNT(I,J,K) = LCOUNT(I,J,K) + 1
   25 CONTINUE
C
C     CHECK FOR ERRORS IN READIND IN VOTEK, VOTEN
C
      DO 28 I=1,5
      DO 28 J=1,10
      DO 28 K=1,10
      IF (LCOUNT(I,J,K)) 27,28,29
   27 IF (LCOUNT(I,J,K)+111) 29,28,29
   28 CONTINUE
      GO TO 30
   29 IA = I - 1
      JA = J - 1
      KA = K - 1
      PRINT 301,IA,JA,KA,LCOUNT(I,J,K)
      CALL EXIT
C
C     COMPUTE STATE-BY-STATE RESULTS
C
   30 DO 33 IALL=1,1628
      I = II(IALL) + 1
      J = JJ(IALL) + 1
      K = KK(IALL) + 1
      M = MM(IALL)
      IF (LCOUNT(I,J,K)) 60,31,31
   60 PRINT 302, II(IALL),JJ(IALL),KK(IALL),MM(IALL),LCOUNT(I,J,K)
      GO TO 33
   31 VK(M,1) = XK1(I,J,K)*TPRIME(IALL,1) + VK(M,1)
      VN(M,1) = XN1(I,J,K)*TPRIME(IALL,1) + VN(M,1)
      VK(M,2) = XK2(I,J,K)*TPRIME(IALL,2) + VK(M,2)
      VN(M,2) = XN2(I,J,K)*TPRIME(IALL,2) + VN(M,2)
      VK(M,3) = XK3(I,J,K)*TPRIME(IALL,3) + VK(M,3)
      VN(M,3) = XN3(I,J,K)*TPRIME(IALL,3) + VN(M,3)
      VK(M,4) = XK1(I,J,K)*TPRIME(IALL,1) + XK2(I,J,K)*TPRIME(IALL,2) +
     1 XK3(I,J,K)*TPRIME(IALL,3) + VK(M,4)
      VN(M,4) = XN1(I,J,K)*TPRIME(IALL,1) + XN2(I,J,K)*TPRIME(IALL,2) +
     1 XN3(I,J,K)*TPRIME(IALL,3) + VN(M,4)
      SUM(M,4) = TPRIME(IALL,1) + TPRIME(IALL,2) + TPRIME(IALL,3)
     1 + SUM(M,4)
      DO 32 L=1,3
   32 SUM(M,L) = TPRIME(IALL,L) + SUM(M,L)
      LCOUNT(I,J,K) = LCOUNT(I,J,K) + 1
   33 MCOUNT(M) = MCOUNT(M) + 1
      DO 36 M=1,48
      DO 35 L=1,4
      VK(M,L) = VK(M,L)/SUM(M,L)
      VN(M,L) = VN(M,L)/SUM(M,L)
      VKNORM(M,L) = VK(M,L)/(VK(M,L) + VN(M,L))
   35 VNNORM(M,L) = 1.0 - VKNORM(M,L)
   36 VOTE(M) = VKNORM(M,4)
C
C     CHECK FOR ERRORS IN COMPUTATION
C
   39 DO 46 M=1,48
      IF (M-5) 40,40,41
   40 IF (MCOUNT(M)-16) 61,42,61
   61 PRINT 303, M,MCOUNT(M)
      GO TO 42
   41 IF (MCOUNT(M)-36) 62,42,62
   62 PRINT 304, M,MCOUNT(M)
   42 DO 45 L=1,4
      IF (VK(M,L)) 63,43,43
   63 PRINT 305, M,L,VK(M,L)
      VK(M,L) = 0.0
   43 IF (VN(M,L)) 64,44,44
   64 PRINT 306, M,L,VN(M,L)
      VN(M,L) = 0.0
   44 IF (VK(M,L)+VN(M,L)-1.0) 45,45,65
   65 PRINT 307, M,L,VK(M,L),M,L,VN(M,L)
      ADJ = (VK(M,L) + VN(M,L) - 1.0)/2.0
      VK(M,L) = VK(M,L) - ADJ
      VN(M,L) = VN(M,L) - ADJ
   45 CONTINUE
      IF (SUM(M,4)-SUM(M,1)-SUM(M,2)-SUM(M,3)) 66,46,66
   66  CONTINUE
   46 CONTINUE
      DO 56 I=1,5
      DO 56 J=1,10
      DO 56 K=1,10
      IF (LCOUNT(I,J,K)) 56,50,50
   50 GO TO (51,52,53,54,55),I
   51 IF (LCOUNT(I,J,K)-5) 71,56,71
   52 IF (LCOUNT(I,J,K)-9) 72,56,72
   53 IF (LCOUNT(I,J,K)-11) 73,56,73
   54 IF (LCOUNT(I,J,K)-12) 74,56,74
   55 IF (LCOUNT(I,J,K)-11) 75,56,75
   56 CONTINUE
      GO TO 80
   71 ITEM = 5
      GO TO 76
   72 ITEM = 9
      GO TO 76
   73 ITEM = 11
      GO TO 76
   74 ITEM = 12
      GO TO 76
   75 ITEM = 11
   76 IA = I - 1
      JA = J - 1
      KA = K - 1
      PRINT 309, IA,JA,KA,LCOUNT(I,J,K),ITEM
      GO TO 56
C
C     COMPUTE CORRELATION AND WRITE OUTPUT
C
   80 PRINT 310, IS,CSHIFT
      CALL VOTCOR(KAPPA1,KAPPA2,WEIGHT,VOTE,VKACT)
      PUNCH 9999,VOTE
9999  FORMAT(12F6.5)
      PRINT 315,((NAME(M),VKACT(M),VOTE(M)),M=1,48)
      PRINT 311
      WRITE OUTPUT TAPE 2,312,(TITLE(N),N=1,24),IS,CSHIFT,(NAME(M),
     1(VK(M,L),
     2VN(M,L),L=1,4),M=1,48)
      WRITE OUTPUT TAPE 2,313,(TITLE(N),N=1,24),IS,CSHIFT,
     1 (NAME(M),(VKNORM(M,
     2L),VNNORM(M,L) ,L=1,4),M=1,48)
      IS = IS + 1
      IF (NJOB-IS) 81,5,5
C
C     END OF RUN PROCEDURE
C
   81 IF (INPUT1-1) 83,82,82
   82 REWIND 9
   83 IF (INPUT2-1) 85,84,84
   84 REWIND 10
   85 PRINT 314
   86 CALL EXIT
C
C     FORMAT SPECIFICATIONS
C
  200 FORMAT (12A6/12A6)
  201 FORMAT (5I10/12A6/12A6/(12F6.5))
  300 FORMAT (93H1SIMULMATICS PROJECT, PROGRAM TO PRODUCE STATE-BY-STATE
     1 SIMULATION RESULTS, NOW IN OPERATION.//12A6/12A6/1H1)
  301 FORMAT (39H ERROR IN READING VOTEK, VOTEN. LCOUNT(I1,1H,I1,1H,I1,
     13H) =I4,17H. RUN TERMINATED.)
  302 FORMAT (10H FOR CELL 3I1,10H IN STATE I2,10H, LCOUNT =I5,41H. VK,
     1VN, SUM COMPUTED WITHOUT THIS CELL./1H0)
  303 FORMAT (8H MCOUNT(I2,3H) =I3,18H. IT SHOULD BE 16./1H0)
  304 FORMAT (8H MCOUNT(I2,3H) =I3,18H. IT SHOULD BE 36./1H0)
  305 FORMAT (4H VK(I2,1H,I1,4H) = F8.5,29H. IT WILL BE SET EQUAL TO 0.0
     1/1H0)
  306 FORMAT (4H VN(I2,1H,I1,4H) = F8.5,29H. IT WILL BE SET EQUAL TO 0.0
     1/1H0)
  307 FORMAT (4H VK(I2,1H,I1,4H) = F8.5,8H AND VN(I2,1H,I1,4H) = F8.5,
     137H. THEY WILL BE ADJUSTED TO SUM TO 1.0/1H0)
  308 FORMAT (5H SUM(I2,21H,L) FOR L = 1,2,3 IS 3F7.4,29H, WHICH DO NOT
     1ADD UP TO SUM(I2,5H,4) = F7.0/1H0)
  309 FORMAT (8H LCOUNT(I1,1H,I1,1H,I1,3H) =I3,17H. IT SHOULD EQUALI3//)
  310 FORMAT (30H1CORRELATIONS FOLLOW FOR CYCLEI3,35H, WITH THE SHIFT PA
     1RAMETER EQUAL TOF8.5/)
  311 FORMAT (1H1)
  312 FORMAT (1H1,12A6/12A6/1H 20X, 12HOUTPUT CYCLEI3,20H.  SHIFT PARAME
     1TER =F8.5/1H028X,59HKENNEDY, NIXON VOTES AS PERCENTAGES OF ELIGIBL
     2E ELECTORATE./1H013X,9HDEMOCRATS14X,11HREPUBLICANS13X,12HINDEPENDE
     3NTS27X,5HTOTAL/6H STATE5X/
     4               5H  NO.9X,7HKENNEDY6X,5HNIXON6X,7HKENNEDY6X,5HNIXON
     56X,7HKENNEDY6X,5HNIXON18X,7HKENNEDY6X,5HNIXON/1H0/(1XA6 ,6F12.5,12
     6X,2F12.5))
  313 FORMAT (1H1,12A6/12A6/1H 20X,  12HOUTPUT CYCLEI3,20H.  SHIFT PARAM
     1ETER =F8.5/1H028X,54HKENNEDY, NIXON VOTES AS PERCENTAGES OF TWO-PA
     2RTY VOTE./1H013X,9HDEMOCRATS14X,    11HREPUBLICANS13X,12HINDEPENDE
     3NTS27X,5HTOTAL/6H STATE5X/
     4               5H  NO.9X,7HKENNEDY6X,5HNIXON6X,7HKENNEDY6X,5HNIXON
     56X,7HKENNEDY6X,5HNIXON18X,7HKENNEDY6X,5HNIXON/1H0/(1XA6 ,6F12.5,12
     6X,2F12.5))
  314 FORMAT (1H140X,11HEND OF RUN.)
 315  FORMAT(50H ACTUAL AND PREDICTED KENNEDY VOTE FOR EACH STATE   /
     128H STATE   ACTUAL   PREDICTED   /  (1XA6,F8.5,F9.5   ) )
C
      END
File Name: box1batch2.bin, Fingerprint: 70c5bb-358f00
