' Copyright   Gerald L. O'Barr   flaco@access1.net
' Please Read:                   http://www.access1.net/flaco
' Read Pete Brown's Aether FAQ at:
' http://magna.com.au/~prfbrown/aeth_faq.htm
'   And Jan 99 issue of Physics Today about the ether!

' This is version 3.2, which allows the time to be slowed down
' so that you can see the interactions take place.
' You can also, if you desire, do your own input by choosing 'figure 5.'
' If you do this, start out using only small changes from the original figures.
' Please know that this program has many limits.
' The ether fields enter from 0 and from 4000.
' 600 mass units is the dividing point between 'reducers' and 'expanders'
' in terms of the diversity or distribution functions or effects on the ether.
' Any changes that get near any of these boundaries might run into problems!
' Please ask questions!!!!!!    Thanks!!!!!!!!!

STR:
    DIM F(6, 100, 5): DIM S(2, 9, 9): DIM A(100, 4): DIM B(100, 4)
    CLEAR : SCREEN 0
    INPUT "Time control function, 10 to 500 to 5000, fast to medium to slow:"; NNT
    GOTO INP1

    ' At Theory Calculation
PRC:
    TML = 99999!: TMR = 99999!
    FOR I = 1 TO NNT
      zzz = COS(I) * SIN(I)          ' Delay loop
    NEXT I
    FOR I = 1 TO 4
      TH = (FL(I, 3) * FL(I, 4) - VL * TL + PL - FL(I, 5)) / (FL(I, 3) - VL)
      IF TH < TML THEN TML = TH: NML = I
    NEXT
    FOR I = 4 TO 6:
      IF NOT F(I, N(I), 2) < 1 THEN
        TH = (VL * TL - F(I, N(I), 3) * F(I, N(I), 4) + F(I, N(I), 5) - PL) / (VL - F(I, N(I), 3))
        IF TH < TML THEN TML = TH: NML = I + 1
      END IF
    NEXT
    FOR I = 1 TO 4
      TH = (FR(I, 3) * FR(I, 4) - VR * TR + PR - FR(I, 5)) / (FR(I, 3) - VR)
      IF TH < TMR THEN TMR = TH: NMR = I
    NEXT
    FOR I = 1 TO 3:
      IF NOT F(I, N(I), 2) < 1 THEN
        TH = (VR * TR - F(I, N(I), 3) * F(I, N(I), 4) + F(I, N(I), 5) - PR) / (VR - F(I, N(I), 3))
        IF TH < TMR THEN TMR = TH: NMR = I + 4
      END IF
    NEXT
    TH = TMR: IF TML < TH THEN TH = TML
    IF PL + (TH - TL) * VL > PR + (TH - TR) * VR THEN GOTO PRC40
    IF TML < TMR THEN GOTO PRC20
    PR = PR + (TMR - TR) * VR: TR = TMR: NR = NR + 1
    IF NMR < 5 THEN GOTO PRC10
    I = 1: IF MR > 600 THEN I = 2
    L = NMR - 4: M1 = F(L, N(L), 2)
    J = (M1 - M) / d + 5: K = (MR - MR0) / d + 5: S = S(I, J, K) * d
    V1 = F(L, N(L), 3)
    F(L, N(L), 2) = 0
    V = (M1 * V1 + MR * VR - (V1 - VR) * SQR(M1 * MR * (M1 - S) / (MR + S))) / (M1 + MR)
    VR = V: N(L) = N(L) + 1: C2 = C6: IF MR = MR0 THEN C2 = C7
    IF MR > MR0 THEN C2 = C8
    MR = MR + S
    IF N(L) > 99 THEN N(L) = 1
    IF NOT NR > 100 THEN
      B(NR, 1) = MR: B(NR, 2) = VR: B(NR, 3) = TR: B(NR, 4) = PR
    END IF
    LINE (X20, Y20)-(PR - TR * VB, TR), C2: X20 = PR - TR * VB: Y20 = TR
    GOTO PRC

PRC10:
    M1 = FR(NMR, 2): V1 = FR(NMR, 3)
    I = 1: IF MR > 600 THEN I = 2
    J = (M1 - M) / d + 5: K = (MR - MR0) / d + 5: S = S(I, J, K) * d
    V = (M1 * V1 + MR * VR - (V1 - VR) * SQR(M1 * MR * (M1 - S) / (MR + S))) / (M1 + MR)
    VV1 = (M1 * V1 + MR * VR + (V1 - VR) * SQR(M1 * MR * (MR + S) / (M1 - S))) / (M1 + MR)
    MR = MR + S: VR = V: C2 = C6: IF MR - S = MR0 THEN C2 = C7
    IF NOT NR > 100 THEN
      B(NR, 1) = MR: B(NR, 2) = VR: B(NR, 3) = TR: B(NR, 4) = PR
    END IF
    FR(NMR, 4) = FR(NMR, 4) + 8 * T: FR(NMR, 1) = FR(NMR, 1) + 1
    L = (M1 - S - M + d) / d + 4: NN(L) = NN(L) + 1: IF MR - S > MR0 THEN C2 = C8
    IF NN(L) > 99 THEN NN(L) = 1
    F(L, NN(L), 2) = M1 - S: F(L, NN(L), 3) = VV1
    F(L, NN(L), 4) = TR: F(L, NN(L), 5) = PR
    LINE (X20, Y20)-(PR - TR * VB, TR), C2: X20 = PR - TR * VB: Y20 = TR
    IF TR > TE THEN WINDOW: GOTO FINAL0
    GOTO PRC

PRC20:
    PL = PL + (TML - TL) * VL: TL = TML: NL = NL + 1
    IF NML < 5 THEN GOTO PRC30
    I = 1: IF ML > 600 THEN I = 2
    L = NML - 1: M1 = F(L, N(L), 2)
    J = (M1 - M) / d + 5: K = (ML - ML0) / d + 5: S = S(I, J, K) * d
    V1 = F(L, N(L), 3)
    F(L, N(L), 2) = 0
    V = (M1 * V1 + ML * VL - (V1 - VL) * SQR(M1 * ML * (M1 - S) / (ML + S))) / (M1 + ML)
    VL = V: N(L) = N(L) + 1: C1 = C3: IF ML = ML0 THEN C1 = C4
    IF ML > ML0 THEN C1 = C5
    ML = ML + S
    IF N(L) > 99 THEN N(L) = 1
    IF NOT NL > 100 THEN
      A(NL, 1) = ML: A(NL, 2) = VL: A(NL, 3) = TL: A(NL, 4) = PL
    END IF
    LINE (X10, Y10)-(PL - TL * VB, TL), C1: X10 = PL - TL * VB: Y10 = TL
    GOTO PRC

PRC30:
     M1 = FL(NML, 2): V1 = FL(NML, 3)
     I = 1: IF ML > 600 THEN I = 2
     J = (M1 - M) / d + 5: K = (ML - ML0) / d + 5: S = S(I, J, K) * d
     V = (M1 * V1 + ML * VL - (V1 - VL) * SQR(M1 * ML * (M1 - S) / (ML + S))) / (M1 + ML)
     VV1 = (M1 * V1 + ML * VL + (V1 - VL) * SQR(M1 * ML * (ML + S) / (M1 - S))) / (M1 + ML)
     ML = ML + S: VL = V: C1 = C3: IF ML - S = ML0 THEN C1 = C4
     IF NOT NL > 100 THEN
       A(NL, 1) = ML: A(NL, 2) = VL: A(NL, 3) = TL: A(NL, 4) = PL
     END IF
     FL(NML, 4) = FL(NML, 4) + 8 * T: FL(NML, 1) = FL(NML, 1) + 1
     L = (M1 - S - M + d) / d + 1: NN(L) = NN(L) + 1: IF ML - S > ML0 THEN C1 = C5
     IF NN(L) > 99 THEN NN(L) = 1
     F(L, NN(L), 2) = M1 - S: F(L, NN(L), 3) = VV1
     F(L, NN(L), 4) = TL: F(L, NN(L), 5) = PL
     LINE (X10, Y10)-(PL - TL * VB, TL), C1: X10 = PL - TL * VB: Y10 = TL
     GOTO PRC

PRC40:
     TX = (PL - PR + TR * VR - TL * VL) / (VR - VL)
     PL = PL + (TX - TL) * VL: PR = PL
     TL = TX: TR = TX: VX = VR: VR = VL: VL = VX
     MX = MR: MR = ML: ML = MX: NX = NR: NR = NL: NL = NX
     LINE (X20, Y20)-(PL - TL * VB, TL), 15
     LINE (X10, Y10)-(PL - TL * VB, TL), 15
     X20 = PL - TL * VB: X10 = X20: Y20 = TL: Y10 = TL
     C3X = C3: C4X = C4: C5X = C5: C3 = C6: C4 = C7: C5 = C8
     C6 = C3X: C7 = C4X: C8 = C5X: I = MCR: MCR = MCL: MCL = I
     GOTO PRC
    
     ' Final Processing
FINAL0:
     AL = (A(88, 2) - A(80, 2)) / (A(88, 3) - A(80, 3))
     AR = (B(88, 2) - B(80, 2)) / (B(88, 3) - B(80, 3))

FINAL1:
     PRINT "FIGURE "; F1; ". "; N$; "  HIT ENTER TO CONTINUE"
     PRINT "LEFT BODY ACCEL. = "; AL; "  RIGHT BODY ACCEL. = "; AR
     PRINT "ML="; ML0; " VL="; VL0; "  MR="; MR0; " VR="; VR0;
     PRINT " LB ="; GS; " RB ="; GE; " TS = "; TS; " TE = "; TE;
     INPUT "", A
FINAL2:
     IF A = 1 THEN GOTO STR
     PRINT " d = "; d; ".    ENTER 1 FOR A NEW RUN, 2 to stop!"
     PRINT "HIT ENTER KEY TO RETURN TO ORIGINAL INFORMATION.  ";
     INPUT "", A
     IF A = 2 THEN END
     IF A > 0 THEN GOTO FINAL2
     GOTO FINAL1

     ' Initial Input Data processing
INP1:
     CLS : PRINT : PRINT : PRINT "   Welcome to O'Barr's At Program"
     PRINT : N$ = "O'Barr 3.2, 13 Dec 99 (3.1: 18 Aug 1994)"
     PRINT "     Version: "; N$
     KEY OFF: d$ = CHR$(27): PRINT : PRINT
     PRINT "  Input 2 for FIGURE 2: Two 800 bodies, attraction (gravity like)."
     PRINT "  Input 3 for FIGURE 3: Two 400 bodies, repulsion."
     PRINT "  Input 4 for FIGURE 4: 400 body chasing 800 body, translation."
     PRINT "  Input 5 for your own parameters.": PRINT
DO:
       PRINT : INPUT "  CHOOSE FIGURE, Input 2, 3 or 4, or 5: ", F1
       PRINT
       IF F1 = 2 THEN ML = 800: VL = 3.6: PL = 1990: MR = 800: VR = -3.6: PR = 2010: GOTO INP2
       IF F1 = 3 THEN ML = 400: VL = -8: PL = 1946: MR = 400: VR = 8: PR = 2052: GOTO INP2
       IF F1 = 4 THEN ML = 400: VL = 6.8: PL = 2025: MR = 800: VR = 3.8: PR = 2052: GOTO INP2
       IF F1 = 5 THEN GOTO INP2
       IF F1 = 0 THEN END            ' Modified
     LOOP

INP2:
     M = 100: V0 = 100000!: T = .125: LB = 0: RB = 4000: C3 = 3: C4 = 12: C5 = 5: C6 = 14: C7 = 10: C8 = 1
     d = 1:
     IF F1 = 5 THEN
       PRINT "Chose mass (ML), Velocity (VL) and location (PL) for large particle on left."
       INPUT "   Mass (ML)  (divides at 600) = : ", ML
       INPUT "   Velocity (VL) = ", VL
       INPUT "   Location (PL) (0 to 2000?) = ", PL
       PRINT : PRINT
       PRINT "Chose mass (MR), Velocity (VR) and location (PR) for large particle on right."
       INPUT "   Mass (MR)  (divides at 600) = : ", MR
       INPUT "   Velocity (VR) = ", VR
       INPUT "   Location (PR) (2000 to 4000?) = ", PR
       PRINT : PRINT : PRINT "Warning, Mass exchanged should be a small, whole,"; number.; ""
       INPUT "Choose value of mass exchanged: d (1) = : ", d
     END IF

     FL(1, 2) = M: FL(2, 2) = M: FL(3, 2) = M + d: FL(4, 2) = M - d
     FR(1, 2) = M: FR(2, 2) = M: FR(3, 2) = M + d: FR(4, 2) = M - d
     FL(1, 4) = T: FL(2, 4) = T * 2: FL(3, 4) = T * 5: FL(4, 4) = T * 6
     FOR I = 1 TO 4
       FL(I, 5) = LB: FR(I, 5) = RB
       FR(I, 4) = FL(I, 4) + T * 2
       FL(I, 1) = 1: FR(I, 1) = 1
       FL(I, 3) = V0 * SQR(M / FL(I, 2))
       FR(I, 3) = -V0 * SQR(M / FR(I, 2))
     NEXT
     FOR I = 1 TO 9
       S(1, 4, I) = -1: IF I < 4 THEN S(1, 4, I) = 0
       S(1, 5, I) = 0
       S(1, 6, I) = 1: IF I > 6 THEN S(1, 6, I) = 0
       S(2, 4, I) = 0
       S(2, 5, I) = 1: IF I > 4 THEN S(2, 5, I) = -1
       S(2, 6, I) = 0
     NEXT
     ML0 = ML: VL0 = VL: PL0 = PL: MCL = 400: IF ML > 500 THEN MCL = 800
     MR0 = MR: VR0 = VR: PR0 = PR: MCR = 400: IF MR > 500 THEN MCR = 800

     CLS : PRINT
     PRINT : PRINT N$; ":"; " THE PARTICLES IN FIGURE"; F1; "ARE:": PRINT
     PRINT "             (1)      (2)        (3)          (4)        (5)"
     PRINT "              N       MASS     VELOCITY       TIME     POSITION "
     PRINT :
     PRINT " LEFT  ";
     FOR I = 1 TO 5: PRINT USING "########.##"; FL(1, I); : NEXT: PRINT :
     PRINT " FIELD ";
     FOR I = 1 TO 5: PRINT USING "########.##"; FL(2, I); : NEXT: PRINT :
     PRINT "  ATS  ";
     FOR I = 1 TO 5: PRINT USING "########.##"; FL(3, I); : NEXT: PRINT :
     PRINT "       ";
     FOR I = 1 TO 5: PRINT USING "########.##"; FL(4, I); : NEXT: PRINT :
     PRINT :
     PRINT " LEFT BODY    1.00"; : PRINT USING "########.##"; ML0; VL0; TL; PL0
     PRINT " RIGHT BODY   1.00"; : PRINT USING "########.##"; MR0; VR0; TR; PR0
     PRINT : PRINT " RIGHT ";
     FOR I = 1 TO 5: PRINT USING "########.##"; FR(1, I); : NEXT: PRINT :
     PRINT " FIELD ";
     FOR I = 1 TO 5: PRINT USING "########.##"; FR(2, I); : NEXT: PRINT :
     PRINT "  ATS  ";
     FOR I = 1 TO 5: PRINT USING "########.##"; FR(3, I); : NEXT: PRINT :
     PRINT "       ";
     FOR I = 1 TO 5: PRINT USING "########.##"; FR(4, I); : NEXT: PRINT :
     PRINT : PRINT : INPUT "HIT ENTER TO CONTINUE", I

     CLS : PRINT : PRINT : PRINT
     PRINT " THE EXCHANGE OF MASS BETWEEN PARTICLES, TIMES d, ARE:": PRINT
     PRINT : PRINT "   FOR ALL 400 MASS PARTICLES, or WHERE M < 600."
     PRINT : PRINT "S(1,9,9)  2     3     4     5     6     7     8"
     PRINT "         M-3d  M-2d  M-d    M    M+d   M+2d  M+3d"
     PRINT "6   m+d  "; : FOR I = 2 TO 8: PRINT S(1, 6, I); "   "; : NEXT: PRINT :
     PRINT "5    m   "; : FOR I = 2 TO 8: PRINT S(1, 5, I); "   "; : NEXT: PRINT :
     PRINT "4   m-d  "; : FOR I = 2 TO 8: PRINT S(1, 4, I); "   "; : NEXT: PRINT :
     PRINT : PRINT : PRINT "   FOR ALL 800 MASS PARTICLES, or WHERE M > 600."
     PRINT : PRINT "S(2,9,9)  2     3     4     5     6     7     8"
     PRINT "         M-3d  M-2d  M-d    M    M+d   M+2d  M+3d"
     PRINT "6   m+d  "; : FOR I = 2 TO 8: PRINT S(2, 6, I); "   "; : NEXT: PRINT :
     PRINT "5    m   "; : FOR I = 2 TO 8: PRINT S(2, 5, I); "   "; : NEXT: PRINT :
     PRINT "4   m-d  "; : FOR I = 2 TO 8: PRINT S(2, 4, I); "   "; : NEXT: PRINT :
     PRINT
     INPUT "HIT RETURN WHEN READY TO CONTINUE", I
    
     FOR I = 1 TO 6: N(I) = 1: NEXT: PRINT
     TS = 0: TE = 25: GS = 1940: GE = 2060: VB = 0:
     TS1 = 0: TSD = 5: GS1 = 1940: GSD = 20
     IF F1 = 5 THEN
       INPUT "Time of start, TS (0) = ", TS
       INPUT "Time to end, TE (25) = ", TE
       PRINT : PRINT "Graph start point, 0 to less than PL?"
       INPUT "     GS (1940) = ", GS
       PRINT : PRINT "Graph end point, more than PR to 4000?"
       INPUT "     GE (2060) = ", GE
       TS1 = TS: GS1 = GS:
       TSD = (TE - TS) / 5
       GSD = (GE - GS) / 6
     END IF

     SCREEN 9: WINDOW (GS, TS)-(GE, TE)
     VIEW (0, 65)-(639, 349): LINE (GS, TE)-(GE, TS), 7, B
     FOR I = 0 TO (TE - TS) / TSD: LINE (GS, TS1 + I * TSD)-(GE, TS1 + I * TSD): NEXT
     FOR I = 0 TO (GE - GS) / GSD: LINE (GS1 + I * GSD, TE)-(GS1 + I * GSD, TS): NEXT
     X10 = PL: Y10 = TS: X20 = PR: Y20 = TS
     LINE (GS, .75 * TSD)-(GS + GSD / 10, .75 * TSD), C5
     LINE (GS, .5 * TSD)-(GS + GSD / 10, .5 * TSD), C4
     LINE (GS, .25 * TSD)-(GS + GSD / 10, .25 * TSD), C3
     LINE (GE, .75 * TSD)-(GE - GSD / 10, .75 * TSD), C8
     LINE (GE, .5 * TSD)-(GE - GSD / 10, .5 * TSD), C7
     LINE (GE, .25 * TSD)-(GE - GSD / 10, .25 * TSD), C6
     VIEW PRINT 1 TO 3
     GOTO PRC               ' Start calculation