Booswig
03-09-2008, 03:28 AM
With some help of the internet, as starter module from gemma_the_husky, as well as input from this forum, I managed to do a small noise propagation model in access, using a module (visual basic).
I have just added a second noise source, and I realised I effectively just doubled the code, including formulas, variables etc. I need some way to make this easier, as I have to add at least another few noise source points.
I define various functions and variables for the first two noise source point, eg.
' Source Noise Characteristics
Const Source_noise_63 = 115
Const Source_noise_125 = 105
Const Source_noise_250 = 103
Const Source_noise_500 = 97
Const Source_noise_1000 = 92
Const Source_noise_2000 = 85
Const Source_noise_4000 = 80
Const SP_Source_noise_63 = 105
Const SP_Source_noise_125 = 108
Const SP_Source_noise_250 = 110
Const SP_Source_noise_500 = 115
Const SP_Source_noise_1000 = 122
Const SP_Source_noise_2000 = 117
Const SP_Source_noise_4000 = 112
' Source Co-ordinates
Const Source_Xcoord = -12.5 '70852
Const Source_Ycoord = 6.501 '-2843675
Const SP_Source_Xcoord = 4.01 '70852
Const SP_Source_Ycoord = -5.01 '-2843675
etc
I also have various variables
' Some Global Variables used in the functions
Dim Angle_quadrant As Long
Dim yvec As Long
Dim ME_Cor63 As Double
Dim ME_Cor125 As Double
Dim ME_Cor250 As Double
Dim ME_Cor500 As Double
Dim ME_Cor1000 As Double
Dim ME_Cor2000 As Double
Dim ME_Cor4000 As Double
Dim SP_ME_Cor63 As Double
Dim SP_ME_Cor125 As Double
Dim SP_ME_Cor250 As Double
Dim SP_ME_Cor500 As Double
Dim SP_ME_Cor1000 As Double
Dim SP_ME_Cor2000 As Double
Dim SP_ME_Cor4000 As Double
Then I have also a massive
Select Case Pasquill_SC ' pasq_cat
Case 1:
If Wind_vector(x, y) <= -3 Then
ME_Cor63 = 8
ME_Cor125 = 5
ME_Cor250 = 6
ME_Cor500 = 8
ME_Cor1000 = 10
ME_Cor2000 = 6
ME_Cor4000 = 8
ElseIf Wind_vector(x, y) > -3 And Wind_vector(x, y) <= -0.5 Then
.
.
.
and
Select Case Pasquill_SC ' pasq_cat
Case 1:
If SP_Wind_vector(x, y) <= -3 Then
SP_ME_Cor63 = 8
SP_ME_Cor125 = 5
SP_ME_Cor250 = 6
SP_ME_Cor500 = 8
SP_ME_Cor1000 = 10
SP_ME_Cor2000 = 6
SP_ME_Cor4000 = 8
ElseIf SP_Wind_vector(x, y) > -3 And SP_Wind_vector(x, y) <= -0.5 Then
.
.
.
With about 20 functions similar to:
' Correction for Geometric Divergence due to distance
Function Geometric_divergence(x As Long, y As Long) As Double
Geometric_divergence = 10 * (Log(4 * Pie * (Dist_calc(x, y) ^ 2)) / Log(10))
End Function
' Correction for Geometric Divergence due to distance between second point source and receptor
Function SP_Geometric_divergence(x As Long, y As Long) As Double
SP_Geometric_divergence = 10 * (Log(4 * Pie * (SP_Dist_calc(x, y) ^ 2)) / Log(10))
End Function
The first set of code is basically for the first noise source, with the second being for the second noise source point. As can be seen, the only difference is that I added SP_ before everything, and doubled it. For the third point source I will just again double the original code, and add TP_ before it, using FP_ and FSP_ and so forth.
Now, that is messy. Is there a way that I can change the variables and function names with something like {point_name_holder} = 1SP_, SP_, TP_, FP_ and FSP_, and then use something like {point_name_holder}Geometric_divergence(x,y) and {point_name_holder}my_variables so that I do not need to double the code and just change the first few letters in the variable/functions/statements.
It will simplify my code, and make it far less messy than what it is now.
I hope you guys can understand me.
I have just added a second noise source, and I realised I effectively just doubled the code, including formulas, variables etc. I need some way to make this easier, as I have to add at least another few noise source points.
I define various functions and variables for the first two noise source point, eg.
' Source Noise Characteristics
Const Source_noise_63 = 115
Const Source_noise_125 = 105
Const Source_noise_250 = 103
Const Source_noise_500 = 97
Const Source_noise_1000 = 92
Const Source_noise_2000 = 85
Const Source_noise_4000 = 80
Const SP_Source_noise_63 = 105
Const SP_Source_noise_125 = 108
Const SP_Source_noise_250 = 110
Const SP_Source_noise_500 = 115
Const SP_Source_noise_1000 = 122
Const SP_Source_noise_2000 = 117
Const SP_Source_noise_4000 = 112
' Source Co-ordinates
Const Source_Xcoord = -12.5 '70852
Const Source_Ycoord = 6.501 '-2843675
Const SP_Source_Xcoord = 4.01 '70852
Const SP_Source_Ycoord = -5.01 '-2843675
etc
I also have various variables
' Some Global Variables used in the functions
Dim Angle_quadrant As Long
Dim yvec As Long
Dim ME_Cor63 As Double
Dim ME_Cor125 As Double
Dim ME_Cor250 As Double
Dim ME_Cor500 As Double
Dim ME_Cor1000 As Double
Dim ME_Cor2000 As Double
Dim ME_Cor4000 As Double
Dim SP_ME_Cor63 As Double
Dim SP_ME_Cor125 As Double
Dim SP_ME_Cor250 As Double
Dim SP_ME_Cor500 As Double
Dim SP_ME_Cor1000 As Double
Dim SP_ME_Cor2000 As Double
Dim SP_ME_Cor4000 As Double
Then I have also a massive
Select Case Pasquill_SC ' pasq_cat
Case 1:
If Wind_vector(x, y) <= -3 Then
ME_Cor63 = 8
ME_Cor125 = 5
ME_Cor250 = 6
ME_Cor500 = 8
ME_Cor1000 = 10
ME_Cor2000 = 6
ME_Cor4000 = 8
ElseIf Wind_vector(x, y) > -3 And Wind_vector(x, y) <= -0.5 Then
.
.
.
and
Select Case Pasquill_SC ' pasq_cat
Case 1:
If SP_Wind_vector(x, y) <= -3 Then
SP_ME_Cor63 = 8
SP_ME_Cor125 = 5
SP_ME_Cor250 = 6
SP_ME_Cor500 = 8
SP_ME_Cor1000 = 10
SP_ME_Cor2000 = 6
SP_ME_Cor4000 = 8
ElseIf SP_Wind_vector(x, y) > -3 And SP_Wind_vector(x, y) <= -0.5 Then
.
.
.
With about 20 functions similar to:
' Correction for Geometric Divergence due to distance
Function Geometric_divergence(x As Long, y As Long) As Double
Geometric_divergence = 10 * (Log(4 * Pie * (Dist_calc(x, y) ^ 2)) / Log(10))
End Function
' Correction for Geometric Divergence due to distance between second point source and receptor
Function SP_Geometric_divergence(x As Long, y As Long) As Double
SP_Geometric_divergence = 10 * (Log(4 * Pie * (SP_Dist_calc(x, y) ^ 2)) / Log(10))
End Function
The first set of code is basically for the first noise source, with the second being for the second noise source point. As can be seen, the only difference is that I added SP_ before everything, and doubled it. For the third point source I will just again double the original code, and add TP_ before it, using FP_ and FSP_ and so forth.
Now, that is messy. Is there a way that I can change the variables and function names with something like {point_name_holder} = 1SP_, SP_, TP_, FP_ and FSP_, and then use something like {point_name_holder}Geometric_divergence(x,y) and {point_name_holder}my_variables so that I do not need to double the code and just change the first few letters in the variable/functions/statements.
It will simplify my code, and make it far less messy than what it is now.
I hope you guys can understand me.