Ca double spike correction using Excel97/2k

The listing below shows the definition of the function "CaCalc(arguments)" programmed in VBA for MS Excel97/2k. This function is the iterative algorithm for the Ca double spike correction (fig. 2.5). The function requires the input of 5 arguments separated by a semicolon: a spike number, the measured 43Ca/48Ca, 44Ca/48Ca and 40Ca/48Ca ratios of the spiked sample and a logical value (True/False). The logical value is used for the output of either the δ44Ca value (True) or of the 44Ca/40Ca ratio (False). Each used Ca double spike gets a number and its composition has to be defined within the program.

Short overview of the parts of the listing:

linesevent
1+2 Definition of the function 'CaCalc'
4−28 Declaration of the variables and the type of the variables
30 Definition of the value for the end of the iteration
34−38 "Russell"-values as starting parameters for the iterative routine
40−60 Definition of the Ca double spike compositions; as we have two different 43Ca/48Ca double spikes the numbers "1" and "3" are defined
63 setting of the cycles counter
67 Fig. 2.5 equation: (11)
68 Fig. 2.5 equation: (12)
69 Fig. 2.5 equation: (13)
71−72 Fig. 2.5 equation: (1)
73 Fig. 2.5 equation: (2)
74 Fig. 2.5 equation: (3)
75 Fig. 2.5 equation: (4)
76 Fig. 2.5 equation: (5)
77 Fig. 2.5 equation: (6)
78−79 Fig. 2.5 equation: (7)
80−81 Fig. 2.5 equation: (8)
82 Fig. 2.5 equation: (9)
84 Fig. 2.5 equation: (10)
95End of the iterations if one the defined conditions is fulfilled
99+101 Output of the result either as δ-value (line 99) or as 44Ca/40Ca-ratio (line 101).


  1     Static Function CaCalc(Spike As Byte, Mix_4348 As Double,
  2        Mix_4448 As Double, Mix_4048 As Double, Delta As Boolean)
  3    
  4     'Dimensionierung der Variablen
  5     Dim MixCalc_4348 As Double
  6     Dim MixCalc_4448 As Double
  7     Dim MixCalc_4048 As Double
  8     Dim MixCalc_4440 As Double
  9     Dim Spike_4348 As Double
 10     Dim Spike_4448 As Double
 11     Dim Spike_4048 As Double
 12     Dim Spike_4440 As Double
 13     Dim PureSample_4348 As Double
 14     Dim PureSample_4448 As Double
 15     Dim PureSample_4048 As Double
 16     Dim PureSample_4440 As Double
 17     Dim PureSample_4348_recalc As Double
 18     Dim PureSample_4448_recalc As Double
 19     Dim PureSample_4048_recalc As Double
 20     Dim PureSample_4440_recalc As Double
 21     Dim beta As Double
 22     Dim fu As Double
 23     Dim Q40 As Double
 24     Dim Qmean As Double
 25     Dim DeltaQ As Double
 26     Dim Q4840 As Double
 27     Dim Q4844 As Double
 28     Dim Krit As Double
 29    
 30     'Kriterium fuer Beendung der Iteration
 31     Krit = 0.000000001
 32     Dim Counter As Single
 33    
 34     'Russell-Werte
 35     PureSample_4448 = 11.27268628
 36     PureSample_4348 = 0.731146432
 37     PureSample_4048 = 531.5409762
 38     PureSample_4440 = 0.021207558
 39    
 40     'Spike-Daten und Wert auf den normalisiert wurde
 41     Select Case Spike
 42     Case 1 'Bern
 43         If Mix_4348 = 0 Then Mix_4348 = 0.786624
 44         Spike_4348 = 0.78664337
 45         Spike_4448 = 0.048534265
 46         Spike_4048 = 0.147728596
 47         Spike_4440 = 0.328536698
 48     Case 3 'Kaiser-Karl
 49         If Mix_4348 = 0 Then Mix_4348 = 0.750546274
 50         Spike_4348 = 0.750546274
 51         Spike_4448 = 0.044730243
 52         Spike_4048 = 0.151914776
 53         Spike_4440 = 0.294443004
 54     Case Else
 55        If Mix_4348 = 0 Then Mix_4348 = 0.786624
 56         Spike_4348 = 0.78664337
 57         Spike_4448 = 0.048534265
 58         Spike_4048 = 0.147728596
 59         Spike_4440 = 0.328536698
 60     End Select
 61    
 62     'Schleifenzaehler fuer Abbruch der Iteration
 63     Counter = 0
 64    
 65     'Iteration
 66     Do
 67         Q4844 = (Mix_4448 - Spike_4448) / (PureSample_4448 - Mix_4448)
 68         Q4840 = (Mix_4048 - Spike_4048) / (PureSample_4048 - Mix_4048)
 69         Qmean = (Q4844 + Q4840) / 2
 70         DeltaQ = Q4844 - Q4840
 71         MixCalc_4348 = (Spike_4348 + Qmean * PureSample_4348) / _
 72                        (1 + Qmean)
 73         beta = Log(MixCalc_4348 / Mix_4348) / Log(43 / 48)
 74         MixCalc_4048 = Mix_4048 * (40 / 48) ^ beta
 75         MixCalc_4448 = Mix_4448 * (44 / 48) ^ beta
 76         MixCalc_4440 = MixCalc_4448 / MixCalc_4048
 77         Q40 = Qmean * PureSample_4048 / Spike_4048
 78         PureSample_4440_recalc = (1 + 1 / Q40) * MixCalc_4440 - _ 
 79                                  (1 / Q40) * Spike_4440
 80         fu = Log(PureSample_4440_recalc / PureSample_4440) / _ 
 81              Log(44 / 40)
 82         PureSample_4448_recalc = PureSample_4448 * (44 / 48) ^ fu
 83         PureSample_4348_recalc = PureSample_4348 * (43 / 48) ^ fu
 84         PureSample_4048_recalc = PureSample_4048 * (40 / 48) ^ fu
 85         Mix_4448 = MixCalc_4448
 86         Mix_4348 = MixCalc_4348
 87         Mix_4048 = MixCalc_4048
 88         PureSample_4448 = PureSample_4448_recalc
 89         PureSample_4348 = PureSample_4348_recalc
 90         PureSample_4048 = PureSample_4048_recalc
 91         PureSample_4440 = PureSample_4440_recalc
 92         Counter = Counter + 1
 93        
 94     'Ende Iteration bei Erfuellung eines der Kritrien
 95     Loop Until Abs(DeltaQ) < Krit Or Counter = 10
 96    
 97     'eigentliches Ergebnis
 98     If Delta = "Wahr" Then
 99     CaCalc = (PureSample_4440_recalc * 47.153 - 1) * 1000
100     Else:
101     CaCalc = PureSample_4440_recalc
102     End If
103     End Function


Seite zuletzt geändert am 02.10.2004 um 14:42 Uhr.

© 2004−2009 Alexander Heuser