Hi,
I am trying to create a program that outputs the letter value for stability class. On the public table, the final stability class is output as a letter, but in the user created tables it outputs as "NAN". When I update the program to output the final stability class numerically, both the public and user created tables output the same number. Any suggestions as to why the user created tables are outputting NAN instead of the appropriate letter value?
Thanks!
Find the program below:
'Enter the constants for your location
'Constants for sunrise/sunset calcs
Const Latitude=41.5 'Positive for North. Must be between -89.8 and +89.8
Const Longitude=111.88 'Positive for West
Const TimeZone=7 'Positive for West. EST=5, CST=6, MST=7, PST=8
Const DaylightTime=0 'Daylight Savings Time 1=Yes, 0=No
Const TwilightAngle=18 'Civil=6, Nautical=12, Astrological=18
'Constants for Stability Class
Const SiteRoughnessLength=15 'Enter the site roughness length in cm
'Other Constants
Const Pi=3.14159265358979
Const DegToRad=Pi/180
Const RadToDeg=180/Pi
'Sensor Variables
Public WDMAG
Public WDALUM
Public WS10
Public TEnclosure_C
Public BattVolt
'Stability Class Variables
Public Daytime As Boolean
Public i
Public SiteRoughnessCorrection
Public InitialStability(2)
Alias InitialStability(1) = InitialStabilityMAG
Alias InitialStability(2) = InitialStabilityALUM
Public FinalStability(2) As String
Alias FinalStability(1) = FinalStabilityMAG
Alias FinalStability(2) = FinalStabilityALUM
Public SigT(2)
Alias SigT(1) = SigTMAG
Alias SigT(2) = SigTALUM
Public NowMinutes
Public SunriseLST, SunsetLST
'Solar Variables
Public Sunrise As String, Sunset As String
Dim SunriseUTC, SunsetUTC
Dim hh As String, mm As String, ss As String
Dim HourAngleSunrise, HourAngleSunset, SunDeclination
Dim JulianDay, JDFromJulianCent, TimeJulianCent
Dim MeanObliquityOfEcliptic, ObliquityCorrection, SunEqOfCenter, EccentricityEarthOrbit
Dim GeomMeanLongSun, GeomMeanAnomalySun, SunTrueLong, SunApparentLong
Dim A, B, C, e, e0, L0, m, O, t, y
Dim Delta, Epsilon, Lambda, Omega, Theta
Dim EqTime, SolarDec, HourAngle
Dim timeDiff, timeUTC, NewTime, Seconds
Dim mrad , sinm , sin2m , sin3m
Dim sint, sin2L0, cos2L0, sin4L0
Dim latRad, sdRad, HAarg, HA,
Dim JD_Year, JD_Month
Dim CurrentTime(9)
Alias CurrentTime(1) = Year
Alias CurrentTime(2) = Month
Alias CurrentTime(3) = MDay
Alias CurrentTime(4) = Hour
Alias CurrentTime(5) = Minute
Alias CurrentTime(6) = Second
Alias CurrentTime(7) = uSecond
Alias CurrentTime(8) = WeekDay
Alias CurrentTime(9) = Day_of_Year
'Output Tables**********************************************************
DataTable(Temp302,true,-1)
DataInterval(4,5,Min,10)
'Magnesium Vane
WindVector(1,WS10,WDMAG, FP2, 0, 450, 0, 0)
FieldNames ("WSMAG,WDMAG,SigTMAG")
Maximum(1,WS10, FP2, 0, False)
'Aluminum Vane
WindVector(1,WS10,WDALUM, FP2, 0, 450, 0, 0)
FieldNames ("WSALUM,WDALUM,SigTALUM")
'Temp
Average(1,TEnclosure_C, FP2, 0)
EndTable
DataTable(Table302,true,-1)
DataInterval(4,5,Min,10)
'Magnesium Vane
Sample(1,Temp302.WSMAG,FP2)
Sample(1,Temp302.WDMAG,FP2)
Sample(1,Temp302.SigTMAG,FP2)
' Maximum(1,WS10, FP2, 0, False)
Sample(1,Temp302.WS10_Max,FP2)
'Aluminum Vane
Sample(1,Temp302.WSALUM,FP2)
Sample(1,Temp302.WDALUM,FP2)
Sample(1,Temp302.SigTALUM,FP2)
'Temp
' Average(1,TEnclosure_C, FP2, 0)
Sample(1,Temp302.TEnclosure_C_Avg,FP2)
'Stability Class
Sample (1,InitialStabilityMAG,FP2)
Sample (1,InitialStabilityALUM,FP2)
Sample (1,FinalStabilityMAG,FP2)
Sample (1,FinalStabilityALUM,FP2)
EndTable
DataTable(Temp202,true,-1)
DataInterval(14,15,Min,10)
'Magnesium Vane
WindVector(1,WS10,WDMAG, FP2, 0, 450, 0, 0)
FieldNames ("WSMAG,WDMAG,SigTMAG")
Maximum(1,WS10, FP2, 0, False)
'Aluminum Vane
WindVector(1,WS10,WDALUM, FP2, 0, 450, 0, 0)
FieldNames ("WSALUM,WDALUM,SigTALUM")
'Temp
Average(1,TEnclosure_C, FP2, 0)
EndTable
DataTable(Table202,true,-1)
DataInterval(14,15,Min,10)
'Magnesium Vane
Sample(1,Temp202.WSMAG,FP2)
Sample(1,Temp202.WDMAG,FP2)
Sample(1,Temp202.SigTMAG,FP2)
' Maximum(1,WS10, FP2, 0, False)
Sample(1,Temp202.WS10_Max,FP2)
'Aluminum Vane
Sample(1,Temp202.WSALUM,FP2)
Sample(1,Temp202.WDALUM,FP2)
Sample(1,Temp202.SigTALUM,FP2)
'Temp
' Average(1,TEnclosure_C, FP2, 0)
Sample(1,Temp202.TEnclosure_C_Avg,FP2)
'Stability Class
Sample (1,InitialStabilityMAG,FP2)
Sample (1,InitialStabilityALUM,FP2)
Sample (1,FinalStabilityMAG,FP2)
Sample (1,FinalStabilityALUM,FP2)
EndTable
DataTable(Temp102,true,-1)
DataInterval(59,60,Min,10)
'Magnesium Vane
WindVector(1,WS10,WDMAG, FP2, 0, 450, 0, 0)
FieldNames ("WSMAG,WDMAG,SigTMAG")
Maximum(1,WS10, FP2, 0, False)
'Aluminum Vane
WindVector(1,WS10,WDALUM, FP2, 0, 450, 0, 0)
FieldNames ("WSALUM,WDALUM,SigTALUM")
'Temp
Average(1,TEnclosure_C, FP2, 0)
EndTable
DataTable(Table102,true,-1)
DataInterval(59,60,Min,10)
'Magnesium Vane
Sample(1,Temp102.WSMAG,FP2)
Sample(1,Temp102.WDMAG,FP2)
Sample(1,Temp102.SigTMAG,FP2)
' Maximum(1,WS10, FP2, 0, False)
Sample(1,Temp102.WS10_Max,FP2)
'Aluminum Vane
Sample(1,Temp102.WSALUM,FP2)
Sample(1,Temp102.WDALUM,FP2)
Sample(1,Temp102.SigTALUM,FP2)
'Temp
' Average(1,TEnclosure_C, FP2, 0)
Sample(1,Temp102.TEnclosure_C_Avg,FP2)
'Stability Class
Sample (1,InitialStabilityMAG,FP2)
Sample (1,InitialStabilityALUM,FP2)
Sample (1,FinalStabilityMAG,FP2)
Sample (1,FinalStabilityALUM,FP2)
EndTable
'Subroutines***************************************************************
Sub calcJD
If (Month <= 2) Then
JD_Year = Year - 1
JD_Month = Month + 12
Else
JD_Year = Year
JD_Month = Month
EndIf
A = FIX(JD_Year / 100)
B = 2 - A + FIX(A / 4)
JulianDay = FIX(365.25 * (JD_Year + 4716)) + FIX(30.6001 * (JD_Month + 1)) + MDay + B - 1524.5
EndSub
Sub calcJDFromJulianCent(t)
JulianDay = t * 36525 + 2451545
JDFromJulianCent = JulianDay
EndSub
Sub calcTimeJulianCent(JulianDay)
t = (JulianDay - 2451545) / 36525
TimeJulianCent = t
EndSub
Sub calcMeanObliquityOfEcliptic(t)
Seconds = 21.448 - t * (46.815 + t * (0.00059 - t * (0.001813)))
e0 = 23 + (26 + (Seconds / 60)) / 60
MeanObliquityOfEcliptic = e0
EndSub
Sub calcObliquityCorrection(t)
Call calcMeanObliquityOfEcliptic(t)
e0 = MeanObliquityOfEcliptic
Omega = 125.04 - 1934.136 * t
e = e0 + 0.00256 * COS(DegToRad*Omega)
ObliquityCorrection = e
EndSub
Sub calcGeomMeanAnomalySun(t)
m = 357.52911 + t * (35999.05029 - 0.0001537 * t)
GeomMeanAnomalySun = m
EndSub
Sub calcSunEqOfCenter(t)
Call calcGeomMeanAnomalySun(t)
m = GeomMeanAnomalySun
mrad = DegToRad*m
sinm = SIN(mrad)
sin2m = SIN(mrad + mrad)
sin3m = SIN(mrad + mrad + mrad)
C = sinm * (1.914602 - t * (0.004817 + 0.000014 * t)) + sin2m * (0.019993 - 0.000101 * t) + sin3m * 0.000289
SunEqOfCenter = C
EndSub
Sub calcGeomMeanLongSun(t)
L0 = 280.46646 + t * (36000.76983 + 0.0003032 * t)
Do
If (L0 <= 360) AND (L0 >= 0) Then Exit Do
If L0 > 360 Then L0 = L0 - 360
If L0 < 0 Then L0 = L0 + 360
Loop
GeomMeanLongSun = L0
EndSub
Sub calcSunTrueLong(t)
Call calcGeomMeanLongSun(t)
L0 = GeomMeanLongSun
Call calcSunEqOfCenter(t)
C = SunEqOfCenter
O = L0 + C
SunTrueLong = O
EndSub
Sub calcSunApparentLong(t)
Call calcSunTrueLong(t)
O = SunTrueLong
Omega = 125.04 - 1934.136 * t
Lambda = O - 0.00569 - 0.00478 * SIN(DegToRad*Omega)
SunApparentLong = Lambda
EndSub
Sub calcSunDeclination(t)
Call calcObliquityCorrection(t)
e = ObliquityCorrection
Call calcSunApparentLong(t)
Lambda = SunApparentLong
sint = SIN(DegToRad*e) * SIN(DegToRad*Lambda)
Theta = RadToDeg*ASIN(sint)
SunDeclination = Theta
EndSub
Sub calcEccentricityEarthOrbit(t)
e = 0.016708634 - t * (0.000042037 + 0.0000001267 * t)
EccentricityEarthOrbit = e
EndSub
Sub calcEquationOfTime(t)
Call calcObliquityCorrection(t)
Epsilon = ObliquityCorrection
Call calcGeomMeanLongSun(t)
L0 = GeomMeanLongSun
Call calcEccentricityEarthOrbit(t)
e = EccentricityEarthOrbit
Call calcGeomMeanAnomalySun(t)
m = GeomMeanAnomalySun
y = TAN((DegToRad*Epsilon) / 2)
y = y ^ 2
sin2L0 = SIN(2 * (DegToRad*L0))
sinm = SIN(DegToRad*m)
cos2L0 = COS(2 * (DegToRad*L0))
sin4L0 = SIN(4 * (DegToRad*L0))
sin2m = SIN(2 * (DegToRad*m))
EqTime = y * sin2L0 - 2 * e * sinm + 4 * e * y * sinm * cos2L0 - 0.5 * y * y * sin4L0 - 1.25 * e * e * sin2m
EqTime = (RadToDeg*EqTime) * 4
EndSub
Sub calcHourAngleSunrise
latRad = DegToRad*Latitude
sdRad = DegToRad*SolarDec
HAarg = (COS(DegToRad*90.833) / (COS(latRad) * COS(sdRad)) - TAN(latRad) * TAN(sdRad))
HA = (ACOS(COS(DegToRad*90.833) / (COS(latRad) * COS(sdRad)) - TAN(latRad) * TAN(sdRad)))
HourAngleSunrise = HA
EndSub
Sub calcHourAngleSunset
latRad = DegToRad*Latitude
sdRad = DegToRad*SolarDec
HAarg = (COS(DegToRad*90.833) / (COS(latRad) * COS(sdRad)) - TAN(latRad) * TAN(sdRad))
HA = (ACOS(COS(DegToRad*90.833) / (COS(latRad) * COS(sdRad)) - TAN(latRad) * TAN(sdRad)))
HourAngleSunset = -HA
EndSub
Sub calcSunriseUTC
Call calcTimeJulianCent(JulianDay)
t = TimeJulianCent
'First pass to approximate sunrise
Call calcEquationOfTime(t)
Call calcSunDeclination(t)
SolarDec = SunDeclination
Call calcHourAngleSunrise
HourAngle = HourAngleSunrise
Delta = Longitude - (RadToDeg*HourAngle)
timeDiff = 4 * Delta 'In minutes of time
timeUTC = 720 + timeDiff - EqTime 'In minutes
'Second pass includes fractional jDay in gamma calc
Call calcJDFromJulianCent(t)
Call calcTimeJulianCent(JDFromJulianCent + timeUTC / 1440)
NewTime = TimeJulianCent
Call calcEquationOfTime(NewTime)
Call calcSunDeclination(NewTime)
SolarDec = SunDeclination
Call calcHourAngleSunrise
HourAngle = HourAngleSunrise
Delta = Longitude - (RadToDeg*HourAngle)
timeDiff = 4 * Delta
timeUTC = 720 + timeDiff - EqTime 'In minutes
SunriseUTC = timeUTC
EndSub
Sub calcSunsetUTC
Call calcTimeJulianCent(JulianDay)
t = TimeJulianCent
'First calculates sunrise and approx length of Day
Call calcEquationOfTime(t)
Call calcSunDeclination(t)
SolarDec = SunDeclination
Call calcHourAngleSunset
HourAngle = HourAngleSunset
Delta = Longitude - (RadToDeg*HourAngle)
timeDiff = 4 * Delta
timeUTC = 720 + timeDiff - EqTime
'First pass used to include fractional Day in gamma calc
Call calcJDFromJulianCent(t)
Call calcTimeJulianCent(JDFromJulianCent + timeUTC / 1440)
NewTime = TimeJulianCent
Call calcEquationOfTime(NewTime)
Call calcSunDeclination(NewTime)
SolarDec = SunDeclination
Call calcHourAngleSunset
HourAngle = HourAngleSunset
Delta = Longitude - (RadToDeg*HourAngle)
timeDiff = 4 * Delta
timeUTC = 720 + timeDiff - EqTime 'In minutes
SunsetUTC = timeUTC
EndSub
Sub calcSunrise
Call calcJD
Call calcSunriseUTC 'Calculate sunrise for this date
SunriseLST = SunriseUTC - (60 * TimeZone) + (DaylightTime * 60) 'Adjust for time zone and daylight savings time in minutes
hh=INT(SunriseLST/60)
mm=INT(SunriseLST MOD 60): If Len(mm)<2 Then mm = "0" + mm
ss=INT(FRAC(SunriseLST)*60+.5):If Len(ss)<2 Then ss = "0" + ss
Sunrise = hh + ":" + mm + ":" + ss
EndSub
Sub calcSunset
Call calcJD
Call calcSunsetUTC 'Calculate sunset for this date
SunsetLST = SunsetUTC - (60 * TimeZone) + (DaylightTime * 60) 'Adjust for time zone and daylight savings time in minutes
hh=INT(SunsetLST/60)
mm=INT(SunsetLST MOD 60): If Len(mm)<2 Then mm = "0" + mm
ss=INT(FRAC(SunsetLST)*60+.5):If Len(ss)<2 Then ss = "0" + ss
Sunset = hh + ":" + mm + ":" + ss
EndSub
'Stability Class Subroutines
Sub Initial_Stability
'Correction Factors for Sensor Height and Site Roughness
SiteRoughnessCorrection = (SiteRoughnessLength/15)^0.2
'Calculate Initial Stability for both vanes
For i = 1 To 2
Select Case SigT(i)
Case Is >=22.5*SiteRoughnessCorrection
InitialStability(i) = 1
Case Is >=17.5*SiteRoughnessCorrection AND Is <22.5*SiteRoughnessCorrection
InitialStability(i) = 2
Case Is >=12.5*SiteRoughnessCorrection AND Is <17.5*SiteRoughnessCorrection
InitialStability(i) = 3
Case Is >=7.5*SiteRoughnessCorrection AND Is <12.5*SiteRoughnessCorrection
InitialStability(i) = 4
Case Is >=3.8*SiteRoughnessCorrection AND Is <7.5*SiteRoughnessCorrection
InitialStability(i) = 5
Case Is <3.8*SiteRoughnessCorrection
InitialStability(i) = 6
EndSelect
Next i
EndSub
Sub Final_Stability
Call Initial_Stability
Call calcSunrise
Call calcSunset
If SunriseLST <= NowMinutes AND NowMinutes <= SunsetLST Then
Daytime = true
Else
Daytime = false
EndIf
For i = 1 To 2 'Calculate Final Stability for both vanes
Select Case Daytime
Case Is = true 'Daytime
Select Case InitialStability(i)
Case Is = 1 'Initial Stability = 1 & daytime
Select Case WS10
Case Is >=6
FinalStability(i) = "D"
Case Is >=4 AND Is <6
FinalStability(i) = "C"
Case Is >=3 AND Is <4
FinalStability(i) = "B"
Case Is <3
FinalStability(i) = "A"
EndSelect 'Initial Stability = 1 & daytime
Case Is = 2 'Initial Stability = 2 & daytime
Select Case WS10
Case Is >=6
FinalStability(i) = "D"
Case Is >=4 AND Is <6
FinalStability(i) = "C"
Case Is <4
FinalStability(i) = "B"
EndSelect 'Initial Stability = 2 & daytime
Case Is = 3 'Initial Stability = 3 & daytime
Select Case WS10
Case Is >=6
FinalStability(i) = "D"
Case Is <6
FinalStability(i) = "C"
EndSelect 'Initial Stability = 3 & daytime
Case Is >= 4 'Initial Stability = 4-6 & daytime
FinalStability(i) = "D" 'Initial Stability 4-6 & daytime
EndSelect 'InitialStability Case
Case Is = false 'Nighttime
Select Case InitialStability(i)
Case Is = 1 'Initial Stability = 1 & nighttime
Select Case WS10
Case Is >=3.6
FinalStability(i) = "D"
Case Is >=2.9 AND Is <3.6
FinalStability(i) = "E"
Case Is <2.9
FinalStability(i) = "F"
EndSelect 'Initial Stability = 1 & nighttime
Case Is = 2 'Initial Stability = 2 & nighttime
Select Case WS10
Case Is >=3.0
FinalStability(i) = "D"
Case Is >=2.4 AND Is <3.0
FinalStability(i) = "E"
Case Is <2.4
FinalStability(i) = "F"
EndSelect 'Initial Stability = 2 & nighttime
Case Is = 3 'Initial Stability = 3 & nighttime
Select Case WS10
Case Is >=2.4
FinalStability(i) = "D"
Case Is <2.4
FinalStability(i) = "E"
EndSelect 'Initial Stability = 3 & nighttime
Case Is = 4 'Initial Stability = 4 & nighttime
FinalStability(i) = "D"
Case Is = 5 'Initial Stability = 5 & nighttime
Select Case WS10
Case Is >=5
FinalStability(i) = "D"
Case Is <5
FinalStability(i) = "E"
EndSelect 'Initial Stability = 5 & nighttime
Case Is = 6 'Initial Stability = 6 & nighttime
Select Case WS10
Case Is >=5.0
FinalStability(i) = "D"
Case Is >=3.0 AND Is <5.0
FinalStability(i) = "E"
Case Is <3.0
FinalStability(i) = "F"
EndSelect 'Initial Stability = 6 & nighttime
EndSelect 'InitialStability Case
EndSelect 'Daytime Case
Next i
EndSub
'Main Program
BeginProg
Scan(3,Sec, 3, 0)
RealTime(CurrentTime)
NowMinutes = (Hour*60)+Minute+(Second/60)
PulseCount(WS10, 1, 1, 0, 0, 0.0399, 0.27)
VoltSe(WDALUM, 1, mV2500,1, False, 0, 250, 0.144, 0)
VoltSe(WDMAG, 1, mV2500,2, False, 0, 250, 0.144, 0)
Therm108(TEnclosure_C,1,3,VX2,0,_60Hz,1,0)
Battery(BattVolt)
CallTable Temp302
Call Final_Stability
CallTable Table302
CallTable Temp202
Call Final_Stability
CallTable Table202
CallTable Temp102
Call Final_Stability
CallTable Table102
NextScan
EndProg
I just saw it. I was sampling as FP2 and not as string.