Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'Dependencies: none
  2.  
  3. 'Note that all parameters are passed by reference. They _will be changed_.
  4. Sub Interchanger(RT1 As Double, RT2 As Double, RP1 As Double, RP2 As Double, _
  5.     RG1 As Double, RG2 As Double, RG3 As Double, RG4 As Double, RE2 As Double, _
  6.     RT5 As Double, RT6 As Double, RT8 As Double, RT9 As Double, RTE As Double, _
  7.     hasError As Boolean)
  8. 'Transfer interchanger. This is going to be kind of messy.
  9.    Dim T1, T2, P1, P2, G1, G2, G3, G4, E2, T5, T6, T8, T9, TE As Double
  10.     Dim del, delta, T9C As Double
  11.     Dim iDelp5 As Integer 'Fix(del + 0.5) is this now
  12.    Dim iter As Integer
  13.    
  14.     Dim skipToggle As Boolean
  15.     skipToggle = False
  16.    
  17.     T1 = RT1
  18.     T2 = RT2
  19.     P1 = RP1
  20.     P2 = RP2
  21.     G1 = RG1
  22.     G2 = RG2
  23.     G3 = RG3
  24.     G4 = RG4
  25.     E2 = RE2
  26.     T5 = RT5
  27.     T6 = RT6
  28.     T8 = RT8
  29.     'T9 = RT9 In original code, but does nothing. Left for ~posterity~
  30.    TE = RTE
  31.     T9 = T2
  32.     iter = 0
  33.    
  34.     Do
  35.         iter = iter + 1
  36.         T5 = (T9 * (P2 + G4) - T2 * T2) / G3
  37.         T6 = (T1 * E2 * G1 + T9 * (P1 + G3) * (1# - E2)) / (P1 + G3 - G4 * E2)
  38.         T8 = (T1 * G1 + T6 * G4) / (P1 + G3)
  39.         'Escape the loop and skip the piece right afterwards (goto 3)
  40.        If (T8 < T1) Then
  41.             skipToggle = True
  42.             Exit Do
  43.         End If
  44.        
  45.         T9C = (T5 * G3 + T6 * G4 - T8 * G3) / G4
  46.         delta = Abs(T9 - T9C)
  47.         del = 10000# * delta
  48.         iDelp5 = del + 0.5
  49.        
  50.         'Maybe escape the loop and goto 2
  51.        If (iDelp5 <= 1) Then Exit Do
  52.        
  53.         If (iDelp5 > 100) Then
  54.             T9 = T9 + 0.05 * (T9 - T9C)
  55.         ElseIf (iDelp5 > 10) Then
  56.             T9 = T9 + 0.03 * (T9 - T9C)
  57.         ElseIf (iDelp5 > 5) Then
  58.             T9 = T9 + 0.01 * (T9 - T9C)
  59.         ElseIf (iDelp5 > 2) Then
  60.             T9 = T9 + 0.005 * (T9 - T9C)
  61.         Else 'If (iDelp5 > 1)
  62.            T9 = T9 + 0.002 * (T9 - T9C)
  63.         End If
  64.     Loop
  65.    
  66.     'The first segment after the loop, i.e., 2. Skip this if it was the first
  67.    'exit option from the loop.
  68.    If (skipToggle = False) Then
  69.         TE = (T9 - T6) / (T9 - T8)
  70.         hasError = False
  71.     'The second segment after the loop, i.e., 3. This is the bad outcome.
  72.    Else
  73.         hasError = True
  74.     End If
  75.    
  76.     'This gets executed in both outcomes before the return.
  77.    RT1 = T1
  78.     RT2 = T2
  79.     RP1 = P1
  80.     RP2 = P2
  81.     RG1 = G1
  82.     RG2 = G2
  83.     RG3 = G3
  84.     RG4 = G4
  85.     RE2 = E2
  86.     RT5 = T5
  87.     RT6 = T6
  88.     RT8 = T8
  89.     RT9 = T9
  90.     RTE = TE
  91. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement