Public instring As String Public Elevation As Variant Public test As Variant Public indx As Integer Public PauseTime, Start, Finish, TotalTime As Variant Public II As Integer Public III As Integer Public autoquit As Integer Public AZIMUTH1 As Variant Public azoff As String Public eloff As String Public az As Variant Public el As Variant Public novlen As Integer Public poldegraded As Double Public novadata As String Public azstr As String Public elstr As String Public azcent As Double Public azstr1 As Variant Public elstr1 As Variant Public azoff1 As Double Public eloff1 As Double Public celesobj As String Public azstr1val As Double Public elstr1val As Double Public moonaz As Variant Public moonel As Variant Public nova As Integer Public traksm As Integer Public moonsked As Integer Public w2drz As Integer Public relatestr As String Public relrate As Double Public freq As Double Public freqshift As Double Dim Pi As Double Private Sub Form_Load() Pi = 4 * Atn(1) Text8.Text = "0" Text9.Text = "0" Text15.Text = "0" Text16.Text = "0" azcent = CDbl(Text15.Text) Text10.Text = "10368" freqhz = 10368100000# relratestr = "0" relrate = 0 End Sub Private Sub Command2_Click() Close 'Unload Form1 End End Sub Public Sub command3_click() Call NewRotate End Sub Private Sub Command1_Click() 'Send Az Call NewRotate End Sub Private Sub Command4_Click() 'Send El Call NewRotate End Sub Private Sub Command6_Click() 'Zero El Text9.Text = 0 Call NewRotate End Sub Private Sub Command9_Click() Text8.Text = 20 Call NewRotate End Sub Private Sub Command10_Click() Text8.Text = 30 Call NewRotate End Sub Private Sub Command11_Click() Text8.Text = 40 Call NewRotate End Sub Private Sub Command12_Click() Text8.Text = 50 Call NewRotate End Sub Private Sub Command13_Click() Text8.Text = 60 Call NewRotate End Sub Private Sub Command14_Click() Text8.Text = 70 Call NewRotate End Sub Private Sub Command15_Click() Text8.Text = 80 Call NewRotate End Sub Private Sub Command16_Click() Text8.Text = 90 Call NewRotate End Sub Private Sub Command17_Click() Text8.Text = 100 Call NewRotate End Sub Private Sub Command18_Click() Text8.Text = 110 Call NewRotate End Sub Private Sub Command19_Click() Text8.Text = 120 Call NewRotate End Sub Private Sub Command20_Click() Text8.Text = 130 Call NewRotate End Sub Private Sub Command21_Click() Text8.Text = 140 Call NewRotate End Sub Private Sub Command22_Click() Text8.Text = 150 Call NewRotate End Sub Private Sub Command23_Click() Text8.Text = 160 Call NewRotate End Sub Private Sub Command24_Click() Text8.Text = 170 Call NewRotate End Sub Private Sub Command25_Click() Text8.Text = 180 Call NewRotate End Sub Private Sub Command26_Click() Text8.Text = 190 Call NewRotate End Sub Private Sub Command27_Click() Text8.Text = 200 Call NewRotate End Sub Private Sub Command28_Click() Text8.Text = 210 Call NewRotate End Sub Private Sub Command29_Click() Text8.Text = 220 Call NewRotate End Sub Private Sub Command30_Click() Text8.Text = 230 Call NewRotate End Sub Private Sub Command31_Click() Text8.Text = 240 Call NewRotate End Sub Private Sub Command32_Click() Text8.Text = 250 Call NewRotate End Sub Private Sub Command33_Click() Text8.Text = 260 Call NewRotate End Sub Private Sub Command34_Click() Text8.Text = 270 Call NewRotate End Sub Private Sub Command35_Click() Text8.Text = 280 Call NewRotate End Sub Private Sub Command36_Click() Text8.Text = 290 Call NewRotate End Sub Private Sub Command37_Click() Text8.Text = 300 Call NewRotate End Sub Private Sub Command38_Click() Text8.Text = 310 Call NewRotate End Sub Private Sub Command40_Click() Text8.Text = 320 Call NewRotate End Sub Private Sub Command41_Click() Text8.Text = 330 Call NewRotate End Sub Private Sub Command42_Click() Text8.Text = 340 Call NewRotate End Sub Private Sub Command43_Click() Text8.Text = 350 Call NewRotate End Sub Private Sub Command44_Click() Text8.Text = 360 Call NewRotate End Sub Private Sub Command45_Click() Text8.Text = 10 Call NewRotate End Sub Public Sub Command5_Click() 'Start Nova DDE Dim aax(10) nova = 1 On Error GoTo DDE_Nova_Error Text7.LinkMode = 0 Text7.LinkTopic = "NFW32|NFW_DATA" Text7.LinkItem = "NFW_SERVER" Text7.LinkMode = 1 Text7.Text = "TUNE ON" Text7.LinkPoke If Text7.LinkMode = 1 Then label1.BackColor = vbWhite command5.BackColor = vbRed Else: label1.BackColor = vbButtonFace End If startdde: DoEvents label1.Caption = Text7.Text freq = Val(Text10.Text) * 1000000 tmp = label1.Caption ' DDE from Nova appears as string here novlen = Len(tmp) If novlen > 10 Then aax(1) = InStr(1, tmp, "AZ", vbTextCompare) + 3 aax(2) = InStr(1, tmp, "EL", vbTextCompare) + 3 aax(3) = InStr(1, tmp, "RR", vbTextCompare) + 3 azstr = Mid(tmp, aax(1), aax(2) - aax(1) - 3) elstr = Mid(tmp, aax(2), aax(3) - aax(2) - 3) relratestr = Mid(tmp, aax(3), 13) If (Val(relratestr) <> 0) Then relrate = CDbl(relratestr) freqshift = 2 * relrate * -freq * (1 / 299792.458) Text24.Text = Format(freqshift, "######0") End If celesobj = Left(tmp, aax(1) - 4) If (Val(elstr) < 0) Then elstr = "0" Else: elstr = Mid(elstr, 2) End If Text8.Text = Format(Val(azstr), "##0.0") Text9.Text = Format(Val(elstr), "##0.0") If (Val(azstr) > 0 Or Val(elstr) > 0) Then Call NewRotate End If End If GoTo startdde Exit Sub DDE_Nova_Error: Ret = MsgBox("Error Opening the Nova DDE interface, Error: " & Err.Description, vbCritical, "NOva DDE Error") Err.Clear End Sub Private Sub Command7_Click() 'Stop Nova DDE If nova = 1 Then command5.BackColor = vbButtonFace label1.BackColor = vbButtonFace If Text7.LinkMode = 1 Then Text7.Text = "TUNE OFF" Text7.LinkPoke End If nova = 0 End If End Sub Public Sub Command8_Click() 'Set Az Center Let azcent = CDbl(Text15.Text) End Sub Public Sub Command49_Click() 'Set El Offset Let eloff1 = CDbl(Text16.Text) End Sub Public Sub Command50_Click() 'Start TrakSM DDE Dim abx(10) traksm = 1 Text14.LinkMode = 0 On Error GoTo DDE_TrakSM_Error ' Text14.LinkTopic = "Trak_SM|TrakSMServ" ' Text14.LinkItem = "TrakSMItem" ' Text14.LinkMode = 1 'Text14.Text = "TRACK_DDE" 'Text14.LinkPoke 'Text14.Text = "TRACK_MOON" 'Text14.LinkPoke 'If Text14.LinkMode = 1 Then 'label1.BackColor = vbWhite 'Command50.BackColor = vbRed 'Else: label1.BackColor = vbButtonFace 'End If startSMdde: DoEvents 'label1.Caption = Text14.Text 'tmp = label1.Caption ' DDE from TrakSM appears as string here 'tmplen = Len(tmp) 'If tmplen > 12 Then ' abx(1) = InStr(1, tmp, "AZ", vbTextCompare) + 3 ' abx(2) = InStr(1, tmp, "EL", vbTextCompare) + 3 'azstr = Mid(tmp, abx(1), abx(2) - abx(1) - 3) 'elstr = Mid(tmp, abx(2), tmplen - abx(2) - 3) 'If (Val(elstr) < 0) Then 'elstr = "0" 'Else: elstr = elstr 'End If 'Text8.Text = Format(val(azstr),"##0.0") 'Text9.Text = Format(val(elstr),"##0.0") 'End If 'If (Val(azstr) > 0 Or Val(elstr) > 0) Then 'Call NewRotate 'End If GoTo startSMdde Exit Sub DDE_TrakSM_Error: Ret = MsgBox("Error Opening the TrakSM DDE interface, Error: " & Err.Description, vbCritical, "NOva DDE Error") Err.Clear End Sub Public Sub NewRotate() azstr1 = Text8.Text elstr1 = Text9.Text azcent = CDbl(Text15.Text) azoff1 = -azcent azstr1val = CDbl(azstr1) + azoff1 elstr1val = CDbl(elstr1) + eloff1 azrad = Pi * (azstr1val / 180) elrad = Pi * (elstr1val / 180) Denom = Cos(Pi - azrad) Numer = Tan(elrad) TanNewEl = (Numer / Denom) If (Denom = 0) Then newelrad = Pi / 2 Else newelrad = Atn(TanNewEl) End If newEl = Abs(newelrad * 180 / Pi) costhetarad = (Cos(elrad) * Cos(Pi - azrad) * Cos(newelrad)) + (Sin(elrad) * Sin(newelrad)) If (Abs(costhetarad) <> 1) Then thetarad = (2 * Atn(1)) + Atn(-costhetarad / Sqr((-costhetarad * costhetarad) + 1)) ElseIf (costhetarad = 1) Then thetarad = 0 ElseIf (costhetarad = -1) Then thetarad = Pi End If theta = thetarad * 180 / Pi If (azrad > Pi) Then Newaz = 180 + theta - azoff1 Else If (azrad > 0) Then Newaz = 180 - theta - azoff1 Else Newaz = -180 + theta - azoff1 End If End If Newaz = Abs(Newaz) Text1.Text = Format(Newaz, "##0.00") Text5.Text = Format(newEl, "##0.00") Call Command54_Click If w2drz = 1 Then TrakSMItem.Text = celesobj & " AZ:" & Format(Newaz, "##0.0") & " EL:" & Format(newEl, "##0.0") Else TrakSMItem.Text = "" End If PauseTime = 15 ' Set duration. Start = Timer ' Set start time. Do While Timer < Start + PauseTime DoEvents ' Yield to other processes. Loop End Sub Private Sub Command51_Click() 'Stop TrakSM DDE If traksm = 1 Then Command50.BackColor = vbButtonFace label1.BackColor = vbButtonFace If Text14.LinkMode = 1 Then Text14.Text = "TRACK_OFF" Text14.LinkPoke End If traksm = 0 End If End Sub Private Sub command52_click() 'Start W2DRZ DDE w2drz = 1 Command52.BackColor = vbRed TrakSMItem.BackColor = vbWhite End Sub Private Sub command53_click() 'Stop W2DRZ DDE If w2drz = 1 Then Command52.BackColor = vbButtonFace TrakSMItem.BackColor = vbButtonFace w2drz = 0 TrakSMItem.Text = "" End If End Sub Private Sub Command54_Click() ' Text 5 is theta is El theta = CDbl(Text5.Text) * Pi / 180 If (Text5.Text = 180) Then Xa = -1 Xb = 0 Else If (Text5.Text = 90) Then Xa = 0 Xb = 1 Else If (Text5.Text = 270) Then Xa = 0 Xb = -1 Else If (Text5.Text = 0) Then Xa = 1 Xb = 0 Else Xa = Cos(theta) Xb = Sin(theta) End If End If End If End If azcenter1 = Text15.Text azcenter = CDbl(azcenter1) * Pi / 180 'xaxis1, yaxis1, zaxis1 are the coefficients of the axis around which the elevation is rotated Xaxis1 = Cos(azcenter + (Pi / 2)) Yaxis1 = Sin(azcenter + (Pi / 2)) Zaxis1 = 0 zaxisnorm1 = Sqr(Xaxis1 * Xaxis1 + Yaxis1 * Yaxis1 + Zaxis1 * Zaxis1) Xaxis1 = Xaxis1 / zaxisnorm1 Yaxis1 = Yaxis1 / zaxisnorm1 Zaxis1 = Zaxis1 / zaxisnorm1 zaxisnorm1 = Sqr(Xaxis1 * Xaxis1 + Yaxis1 * Yaxis1 + Zaxis1 * Zaxis1) If (Xaxis1 = 0) Then elrot = 90 Else elrot = Atn(Yaxis1 / Xaxis1) * 180 / Pi End If 'X, Y, and Z are the coefficients of the vector pointing to azcenter(x), azcenter(y), El (El = azcenter(z)) X = Cos(azcenter) * Xa Y = Sin(azcenter) * Xa Z = Xb Angmag = Sqr(X * X + Y * Y + Z * Z) X = X / Angmag Y = Y / Angmag Z = Z / Angmag Angmag = Sqr(X * X + Y * Y + Z * Z) ' we have 2 vectors: the vector to azcenter rotated about the elevation rotation axis by theta, and the elevation rotation axis ' these two vectors are orthogonal ' the vector orthogonal to both of them will be the axis of rotation for the azimuth rotator ' the cross product of these two vectors will give a vector orthogonal to both of these vectors ' this is the vector around which the 2nd [aximuth] rotation occurs ' u1 = a2b3 - a3b2 ' u2 = a3b1 - a1b3 ' u3 = a1b2 - a2b1 ' see https://secure.wikimedia.org/wikipedia/en/wiki/Cross_product u1 = Yaxis1 * Z - Zaxis1 * Y u2 = Zaxis1 * X - Xaxis1 * Z u3 = Xaxis1 * Y - Yaxis1 * X umag = Sqr(u1 * u1 + u2 * u2 + u3 * u3) u1 = u1 / umag u2 = u2 / umag u3 = u3 / umag umag = Sqr(u1 * u1 + u2 * u2 + u3 * u3) ' Text 10 is phi is Az phi1 = CDbl(Text1.Text) - CDbl(azcenter1) phi = phi1 * Pi / 180 If (Val(phi1) = 180) Then X1a = -1 X1b = 0 Else If (Val(phi1) = 90) Then X1a = 0 X1b = 1 Else If (Val(phi1) = 270) Then X1a = 0 X1b = -1 Else If (Val(phi1) = 0) Then X1a = 1 X1b = 0 Else If (Val(phi) = 360) Then X1a = 1 X1b = 0 Else X1a = Cos(-phi) X1b = Sin(-phi) End If End If End If End If End If 'https://secure.wikimedia.org/wikipedia/en/wiki/Rotation_matrix for generalized rotation about an arbitrary vector X1 = ((u1 * u1 * (1 - X1a)) + X1a) * X + ((u1 * u2) * (1 - X1a) - (u3 * X1b)) * Y + ((u1 * u3) * (1 - X1a) + u2 * X1b) * Z Y1 = ((u1 * u2) * (1 - X1a) + u3 * X1b) * X + ((u2 * u2 * (1 - X1a) + X1a)) * Y + ((u2 * u3 * (1 - X1a) - u1 * X1b)) * Z Z1 = (((u1 * u3) * (1 - X1a) - u2 * X1b) * X + ((u2 * u3 * (1 - X1a) + u1 * X1b)) * Y + ((u3 * u3 * (1 - X1a) + X1a)) * Z) ang1mag = Sqr(X1 * X1 + Y1 * Y1 + Z1 * Z1) X1 = X1 / ang1mag Y1 = Y1 / ang1mag Z1 = Z1 / ang1mag ang1mag = Sqr(X1 * X1 + Y1 * Y1 + Z1 * Z1) If (X1 = 0) Then az1 = 90 Else If (X1 > 0 And Y1 >= 0) Then az1 = Atn(Y1 / X1) * 180 / Pi Else If (X1 < 0) Then az1 = Atn(Y1 / X1) * 180 / Pi + 180 Else If (X1 > 0 And Y1 < 0) Then az1 = 360 + Atn(Y1 / X1) * 180 / Pi End If End If End If End If If az1 > 360 Then az1 = az1 - 360 End If If Z1 = 0 Then el1 = 0 Else If Z1 = 1 Then el1 = 90 Else If Z1 = -1 Then el1 = -90 Else ''''''''''''''''''el1 = Arcsin(Z1 / Ang1mag) * 180 / pi''''''''''''''''''''' el1 = Atn((Z1) / (Sqr((-(Z1) * (Z1)) + 1))) * 180 / Pi End If End If End If Text13.Text = Format(az1, "##0.000") Text17.Text = Format(Abs(el1), "##0.000") polarization = (Text1.Text - azcent) * Sin(theta) Text20.Text = Format(polarization, "##0.00") & " deg" poldegraded = Abs(Cos(polarization * Pi / 180)) If poldegraded = 0 Then degrad = 0 Else degrad = 20 * Log10(poldegraded) End If Text22.Text = Format(degrad, "##0.00") & " dB" End Sub Private Sub Command55_Click() If w2drz = 1 Then TrakSMItem.Text = "Man" & " AZ:" & Format(Val(Text1.Text), "##0.0") & " EL:" & Format(Val(Text5.Text), "##0.0") Else TrakSMItem.Text = "" End If End Sub Function Log10(number As Double) As Double Log10 = Log(number) / 2.30258509299405 End Function