Hi all,
Below is the program im using at the moment.
Currently the Sun duration is recorded as , lets say 0,37 hours of sun, but i want to have it in hours minutes seconds.
How do i accomplish this? Probably someone can add this function in my program below cos im not that skilled in cr basic...
Thanks in advance.
'CR1000'define all angles in degrees not radians
AngleDegrees
'Declare Variables and Units Dim AirTC_2
Dim SPkPa
Dim Twg
Dim Twpg
Dim Vpg
Dim Vp
Dim SVp
Dim Twch
Dim VpgVpd
Dim Top
Dim Bottom
Dim SVpW
Dim N
Dim WCTF
Dim WCWSMPH
Public BattV
Public Windr
Public Temp
Public Vocht
Public Windskm
Public Rain_mmPublic BP_mbar
Public BP_mbar_Change
Public Temp_Change
Public Vocht_Change
Public SlrW
Public SlrkJ
Public Tot24
Public Windskn
Public Beaufort
Public AvgBeaufort
Public MaxBeaufort
Public Windroos As String
Public Windrichting As String
Public Beaufortnaam As String
Public Windsms
Public SinWindr
Public CosWindr
Public AvgSinWindr
Public AvgCosWindr
Public AvgWindr
Public SunHrs
Public PotSlrW
Public RTime(9)
Public SolPos(5)
Public TdC
Public TwC
Public WR_m
Public TotWR_m
Public TotSunHrs
Public WC_CAlias RTime(1)=Year
Alias RTime(2)=Month
Alias RTime(3)=DayOfMonth
Alias RTime(4)=HourOfDay
Alias RTime(5)=Minutes
Alias RTime(6)=Seconds
Alias RTime(7)=Microseconds
Alias RTime(8)=DayOfWeek
Alias RTime(9)=DayOfYear
Alias SolPos(1)=SolarAzimuth
Alias SolPos(2)=SunElevation
Alias SolPos(3)=HourAngle
Alias SolPos(4)=Declination
Alias SolPos(5)=AirMassUnits SunHrs=hours
Units BattV=Volts
Units Windr=Deg
Units Temp=DegC
Units Vocht=%
Units Windskm=kph
Units Windskn=kts
Units Rain_mm=mmUnits BP_mbar=mbar
Units Windsms=m/s
Units SlrW=W/m^2
Units SlrkJ=kJ/m^2
Units Windroos=String
Units Windrichting=String
Units Beaufortnaam=String
Units PotSlrW=W/m^2
Units TdC=Deg C
Units TwC=Deg C
Units WR_m=meters
Units WC_C=Deg C
Units Year=years
Units Month=months
Units DayOfMonth=days
Units HourOfDay=hours
Units Minutes=minutes
Units Seconds=seconds
Units Microseconds=microseconds
Units DayOfWeek=days
Units DayOfYear=days
Units SolarAzimuth=degrees
Units SunElevation=degrees
Units HourAngle=radians
Units Declination=radians
Units AirMass=unitless'Define Data TablesDataTable(TableOneMin,True,-1)
DataInterval(0,1,min,0)
WindVector (1,Windskm,Windr,IEEE4,False,0,0,1)
FieldNames ("Windskm,Windr")
Sample(1,Windroos,String)
FieldNames ("Windroos")
Maximum(1,Windskm,IEEE4,False,True)
FieldNames ("MaxWindskm")
SampleMaxMin (1,Windr,IEEE4,False)
Average(1,Temp,IEEE4,False)
FieldNames ("Temp")
Maximum(1,Temp,IEEE4,False,True)
FieldNames ("MaxTemp")
Minimum(1,Temp,IEEE4,False,True)
FieldNames ("MinTemp")
Average(1,Vocht,IEEE4,False)
FieldNames ("Vocht")
Maximum(1,Vocht,IEEE4,False,True)
FieldNames ("MaxVocht")
Minimum(1,Vocht,IEEE4,False,True)
FieldNames ("MinVocht")
Average(1,SlrW,IEEE4,False)
FieldNames ("SlrW")
Maximum(1,SlrW,IEEE4,False,True)
FieldNames ("MaxSlrW")
Totalize(1,SunHrs,IEEE4,False)
Average(1,Windsms,IEEE4,False)
FieldNames ("Windsms")
Maximum(1,Windsms,IEEE4,False,True)
FieldNames ("MaxWindsms")
Sample(1,TdC,IEEE4)
Sample(1,TwC,IEEE4)
Totalize(1,WR_m,IEEE4,False)
Sample(1,WC_C,IEEE4)
Average(1,Windskn,IEEE4,False)
FieldNames ("Windskn")
Maximum(1,Windskn,IEEE4,False,True)
FieldNames ("MaxWindskn")
Sample (1,AvgBeaufort,IEEE4)
FieldNames ("Beaufort")
Maximum (1,Beaufort,IEEE4,False,True)
FieldNames ("MaxBeaufort")
Average(1,BP_mbar,IEEE4,False)
FieldNames ("Baro")
Sample(1,Tot24,IEEE4)
FieldNames ("Tot24")
Sample(1,TotSunHrs,IEEE4)
FieldNames ("TotSunHrs")
Sample(1,PotSlrW,IEEE4)
FieldNames ("PotSlrW")
Average(1,TdC,IEEE4,False)
FieldNames ("Dauw")
Maximum(1,TdC,IEEE4,False,True)
FieldNames ("MaxDauw")
Minimum(1,TdC,IEEE4,False,True)
FieldNames ("MinDauw")
Average(1,TwC,IEEE4,False)
FieldNames ("Nattebol")
Maximum(1,TwC,IEEE4,False,True)
FieldNames ("MaxNattebol")
Minimum(1,TwC,IEEE4,False,True)
FieldNames ("MinNattebol")EndTableDataTable(TableTenMin,True,-1)
DataInterval(0,10,min,0)
WindVector (1,Windskm,Windr,IEEE4,False,0,0,1)
FieldNames ("Windskm,Windr")
Sample(1,Windroos,String)
FieldNames ("Windroos")
Maximum(1,Windskm,IEEE4,False,True)
FieldNames ("MaxWindskm")
SampleMaxMin (1,Windr,IEEE4,False)
Average(1,Temp,IEEE4,False)
FieldNames ("Temp")
Maximum(1,Temp,IEEE4,False,True)
FieldNames ("MaxTemp")
Minimum(1,Temp,IEEE4,False,True)
FieldNames ("MinTemp")
Average(1,Vocht,IEEE4,False)
FieldNames ("Vocht")
Maximum(1,Vocht,IEEE4,False,True)
FieldNames ("MaxVocht")
Minimum(1,Vocht,IEEE4,False,True)
FieldNames ("MinVocht")
Average(1,SlrW,IEEE4,False)
FieldNames ("SlrW")
Average(1,Windsms,IEEE4,False)
FieldNames ("Windsms")
Maximum(1,Windsms,IEEE4,False,True)
FieldNames ("MaxWindsms")
Average(1,Windskn,IEEE4,False)
FieldNames ("Windskn")
Maximum(1,Windskn,IEEE4,False,True)
FieldNames ("MaxWindskn")
Sample (1,AvgBeaufort,IEEE4)
FieldNames ("Beaufort")
Maximum (1,Beaufort,IEEE4,False,True)
FieldNames ("MaxBeaufort")
Average(1,BP_mbar,IEEE4,False)
FieldNames ("Baro")
Sample(1,Tot24,IEEE4)
FieldNames ("Tot24")
Sample(1,TotSunHrs,IEEE4)
FieldNames ("TotSunHrs")
EndTable
DataTable (Test,True,0)
DataInterval (0,1,Sec,0)
Sample (1,BP_mbar,IEEE4)
Sample (1,BP_mbar_Change,IEEE4)
EndTableDataTable (TestTemp,True,0)
DataInterval (0,1,Sec,0)
Sample (1,Temp,IEEE4)
Sample (1,Temp_Change,IEEE4)
EndTableDataTable (TestVocht,True,0)
DataInterval (0,1,Sec,0)
Sample (1,Vocht,IEEE4)
Sample (1,Vocht_Change,IEEE4)
EndTable'Main Program
BeginProg
Scan(1,Sec,1,0)'Default Datalogger Battery Voltage measurement BattV
Battery(BattV)
'Generic 4-20 mA Input measurement Windr
VoltDiff(Windr,1,mV2500,2,True,0,_60Hz,0.18,0)
'Generic 4-20 mA Input measurement Temp
VoltDiff(Temp,1,mV2500,3,True,0,_60Hz,0.05,-65)
'Generic 4-20 mA Input measurement Vocht
VoltDiff(Vocht,1,mV2500,4,True,0,_60Hz,0.05,-25)
'Generic 4-20 mA Input measurement Windskm
VoltDiff(Windskm,1,mV2500,1,True,0,_60Hz,0.081035,-39.9875)
'Generic Tipping Bucket Rain Gauge measurement Rain_mm
PulseCount(Rain_mm,1,1,2,0,0.2,0)
'PTB101B Barometric Pressure Sensor (CSL) measurement BP_mbar
VoltDiff(BP_mbar,1,mV2500,6,1,0,_60Hz,0.184,600)
'CM3 Pyranometer (CSL) measurements SlrkJ and SlrW
VoltDiff(SlrW,1,mV250,7,True,0,_60Hz,1,0)
'User Entered Calculation
Windr = (Windr-220+360)MOD 360
If Windr>360 Then Windr =Windr-360
If Windr <0 Then Windr = Windr+360
If Windr>=360 Then Windr=0If SlrW<0 Then SlrW=0
SlrkJ=SlrW*0.04330879
SlrW=SlrW*43.30879
'Calculate Sunshine Hours
'Get current time
RealTime(RTime(1))
'Calculate solar position
SolarPosition(SolPos(),RTime(),2*3600,51.483169,3.622959,0,BP_mbar,Temp)
'Calculate potential radiation for time && position (multiply sine of solar elevation angle by solar constant 1373)
PotSlrW=SIN(SunElevation)*1000
'If the measured value (W/m^2) is greater than 0.4 * the potential solar radiation (W/m^2)
'and the sine of the sun elevation angle (degrees) is great than 0.1 (elevation angle of 6 degrees)
'than it has been sunny for the current scan.
If SlrW>0.8*PotSlrW AND SIN(SunElevation)>0.1 Then
'Calculate sun hours for scan time in seconds
SunHrs=1/3600*1
Else
'Set sun hours for scan time in seconds to 0
SunHrs=0
If PotSlrW<0 Then PotSlrW=0
EndIf
'Dew Point and Wet-Bulb calculation prep
AirTC_2=Temp
SPkPa=101.325
SatVP(SVp,AirTC_2)
Vp=Vocht*SVp/100
'Dew Point calculation 'TdC'
DewPoint(TdC,AirTC_2,Vocht)
If TdC>AirTC_2 Or TdC=NAN Then TdC=AirTC_2
'Find Wet-Bulb 'TwC'
Top=AirTC_2
Bottom=TdC
For N = 1 To 25
Twpg=Twg
Twg=((Top-Bottom)/2)+Bottom
WetDryBulb(Vpg,AirTC_2,Twg,SPkPa)
VpgVpd=Vpg-Vp
Twch=ABS(Twpg-Twg)
If VpgVpd>0 Then
Top=Twg
Else
Bottom=Twg
EndIf
If Twch<0.01 Or N=25 Then ExitFor
Next
TwC=Twg
'Wind Run calculation 'WS'
'Convert to meters per second if needed and multiply by the scan rate in seconds
WR_m=Windskm/3.6
'Wind Chill calculation 'WC_C'
WCTF=1.8*Temp+32
WCWSMPH=Windskm*0.621371
WC_C=35.74+0.6215*WCTF-35.75*WCWSMPH^0.16+0.4275*WCTF*WCWSMPH^0.16
If WC_C>WCTF Or WC_C=NAN Then WC_C=WCTF
If WCTF>50 Or WCWSMPH<3 Then WC_C=WCTF
WC_C=(5/9)*(WC_C-32) '24 hour running total calculation Tot24
Tot24=Tot24+Rain_mm
If IfTime(24,1440,Min) Then Tot24=0
'24 hour running total calculation TotWR_m
TotWR_m=TotWR_m+WR_m
If IfTime(24,1440,Min) Then TotWR_m=0
'24 hour running total calculation TotSunHrs
TotSunHrs=TotSunHrs+SunHrs
If IfTime(24,1440,Min) Then TotSunHrs=0
'Calculate 1 Minute Running Average For Wind Direction
SinWindr = SIN(Windr)
CosWindr = COS(Windr)
AvgRun (AvgSinWindr,1,SinWindr,60)
AvgRun (AvgCosWindr,1,CosWindr,60)
AvgWindr = ATN(AvgSinWindr/AvgCosWindr)
If AvgCosWindr < 0 Then
AvgWindr = 180 + AvgWindr
ElseIf AvgSinWindr < 0 Then
AvgWindr = 360 + AvgWindr
EndIf
'PTB101B Barometric Pressure Sensor (CSL) measurement BP_mbar
VoltDiff(BP_mbar,1,mV2500,6,1,0,_50Hz,0.184,600)
PortSet(1,0)
If Test.Record(1,1) > 0 Then
'calculate change for one hour
BP_mbar_Change = BP_mbar - Test.BP_mbar(1,1)
EndIf
'Generic 4-20 mA Input measurement Temp
VoltDiff(Temp,1,mV2500,3,True,0,_60Hz,0.05,-65)
PortSet(1,0)
If TestTemp.Record(1,1) > 0 Then
'calculate change for one hour
Temp_Change = Temp - TestTemp.Temp(1,1)
EndIf'Generic 4-20 mA Input measurement Vocht
VoltDiff(Vocht,1,mV2500,4,True,0,_60Hz,0.05,-25)
PortSet(1,0)
If TestVocht.Record(1,1) > 0 Then
'calculate change for one hour
Vocht_Change = Vocht - TestVocht.Vocht(1,1)
EndIf
'User Entered Calculation
If AvgWindr >= 348.75 AND AvgWindr <= 359.9 OR AvgWindr >= 0 AND AvgWindr <= 11.25 Then
Windroos = "N"
ElseIf AvgWindr > 11.25 AND AvgWindr < 33.25 Then
Windroos = "NNO"
ElseIf AvgWindr > 33.25 AND AvgWindr < 56.25 Then
Windroos = "NO"
ElseIf AvgWindr > 56.25 AND AvgWindr < 78.75 Then
Windroos = "ONO"
ElseIf AvgWindr > 78.75 AND AvgWindr < 101.25 Then
Windroos = "O"
ElseIf AvgWindr > 101.25 AND AvgWindr < 123.75 Then
Windroos = "OZO"
ElseIf AvgWindr > 123.75 AND AvgWindr < 146.25 Then
Windroos = "ZO"
ElseIf AvgWindr > 146.25 AND AvgWindr < 168.75 Then
Windroos = "ZZO"
ElseIf AvgWindr > 168.75 AND AvgWindr < 191.25 Then
Windroos = "Z"
ElseIf AvgWindr > 191.25 AND AvgWindr < 213.75 Then
Windroos = "ZZW"
ElseIf AvgWindr > 213.75 AND AvgWindr < 236.25 Then
Windroos = "ZW"
ElseIf AvgWindr > 236.25 AND AvgWindr < 258.75 Then
Windroos = "WZW"
ElseIf AvgWindr > 258.75 AND AvgWindr < 281.25 Then
Windroos = "W"
ElseIf AvgWindr > 281.25 AND AvgWindr < 303.75 Then
Windroos = "WNW"
ElseIf AvgWindr > 303.75 AND AvgWindr < 326.25 Then
Windroos = "NW"
ElseIf AvgWindr >= 326.25 AND AvgWindr <= 348.75 Then
Windroos = "NNW"
EndIf
'User Entered CalculationIf Windr >= 348.75 AND Windr <= 359.9 OR Windr >= 0 AND Windr <= 11.25 Then
Windrichting = "N"
ElseIf Windr > 11.25 AND Windr < 33.25 Then
Windrichting = "NNO"
ElseIf Windr > 33.25 AND Windr < 56.25 Then
Windrichting = "NO"
ElseIf Windr > 56.25 AND Windr < 78.75 Then
Windrichting = "ONO"
ElseIf Windr > 78.75 AND Windr < 101.25 Then
Windrichting = "O"
ElseIf Windr > 101.25 AND Windr < 123.75 Then
Windrichting = "OZO"
ElseIf Windr > 123.75 AND Windr < 146.25 Then
Windrichting = "ZO"
ElseIf Windr > 146.25 AND Windr < 168.75 Then
Windrichting = "ZZO"
ElseIf Windr > 168.75 AND Windr < 191.25 Then
Windrichting = "Z"
ElseIf Windr > 191.25 AND Windr < 213.75 Then
Windrichting = "ZZW"
ElseIf Windr > 213.75 AND Windr < 236.25 Then
Windrichting = "ZW"
ElseIf Windr > 236.25 AND Windr < 258.75 Then
Windrichting = "WZW"
ElseIf Windr > 258.75 AND Windr < 281.25 Then
Windrichting = "W"
ElseIf Windr > 281.25 AND Windr < 303.75 Then
Windrichting = "WNW"
ElseIf Windr > 303.75 AND Windr < 326.25 Then
Windrichting = "NW"
ElseIf Windr > 326.25 AND Windr < 348.75 Then
Windrichting = "NNW"
EndIf'User Entered Calculation
If Windskm<1 Then
Beaufortnaam = "Stil"
ElseIf Windskm<6 Then
Beaufortnaam = "Zwak"
ElseIf Windskm<12 Then
Beaufortnaam = "zwak"
ElseIf Windskm<20 Then
Beaufortnaam = "Matig"
ElseIf Windskm<29 Then
Beaufortnaam = "Matig"
ElseIf Windskm<39 Then
Beaufortnaam = "Vrij krachtig"
ElseIf Windskm<50 Then
Beaufortnaam = "Krachtig"
ElseIf Windskm<62 Then
Beaufortnaam = "Hard"
ElseIf Windskm<75 Then
Beaufortnaam = "Stormachtig"
ElseIf Windskm<89 Then
Beaufortnaam = "Storm"
ElseIf Windskm<103 Then
Beaufortnaam = "Zware storm"
ElseIf Windskm<117 Then
Beaufortnaam = "Zeer zware storm"
ElseIf Windskm>117 Then
Beaufortnaam = "Orkaan"
EndIf'User Entered CalculationWindskn=(Windskm/1.852)
Windsms=(Windskm/3.6)
If Windskm<1 Then
Beaufort=0
ElseIf Windskm<6 Then
Beaufort=1
ElseIf Windskm<12 Then
Beaufort=2
ElseIf Windskm<20 Then
Beaufort=3
ElseIf Windskm<29 Then
Beaufort=4
ElseIf Windskm<39 Then
Beaufort=5
ElseIf Windskm<50 Then
Beaufort=6
ElseIf Windskm<62 Then
Beaufort=7
ElseIf Windskm<75 Then
Beaufort=8
ElseIf Windskm<89 Then
Beaufort=9
ElseIf Windskm<103 Then
Beaufort=10
ElseIf Windskm<117 Then
Beaufort=11
ElseIf Windskm>117 Then
Beaufort=12
EndIfAvgRun (AvgBeaufort,1,Beaufort,600)
AvgBeaufort = Round (AvgBeaufort,0)
If AvgBeaufort > MaxBeaufort Then MaxBeaufort = AvgBeaufort
CallTable(TableOneMin)
CallTable(TableTenMin)
CallTable (Test)
CallTable (TestTemp)
CallTable (TestVocht)
NextScan
EndProg
Hi Makada,
I'm not an expert, but I've done like that before, may be it'll help you a bit. Place following declarations under variable declarations;
Public TotSun_H, TotSun_M, TotSun_S Public TotSun_HMS As String * 32
And place following codes beolw TotSunHrs caculations;
TotSun_H=INT(TotSunHrs*24) TotSun_M=INT((TotSunHrs*24-TotSun_H)*60) TotSun_S=Round((((TotSunHrs*24-TotSun_H)*60)-TotSun_M)*60,0) TotSun_HMS=FormatFloat(TotSun_H,"%02.00f")+":"+FormatFloat(TotSun_M,"%02.00f")+":"+FormatFloat(TotSun_S,"%02.00f")
Your results will be, for example, if TotSunHrs = 0.37, TotSun_HMS = 08:52:48. Hope this will help. If you want to store this in the tables, replace "TotSunHrs,IEEE4" as "TotSun_HMS,String" in respective tables.
Beside this, I doubt for following codes in your program;
If IfTime(24,1440,Min) Then Tot24=0 If IfTime(24,1440,Min) Then TotWR_m=0 If IfTime(24,1440,Min) Then TotSunHrs=0
I think those will reset at 24 minute after midnight. If you wish to reset at midnight, I sugest to use following codes.
If IfTime(0,1440,Min) Then Tot24=0 If IfTime(0,1440,Min) Then TotWR_m=0 If IfTime(0,1440,Min) Then TotSunHrs=0
Please double check with an expert. Let me know if it works.
Cheers,
Thein
Hi Thein,
Thanks alot for Your input, its running now.
Will Let you know tomorrow because its nighttime right now, so i cant see if its working ok.
Cheers
Mark
Hi Thein,
I see its running in steps of 24 seconds instead of 1...
'CR1000'define all angles in degrees not radians
AngleDegrees
'Declare Variables and Units Dim AirTC_2
Dim SPkPa
Dim Twg
Dim Twpg
Dim Vpg
Dim Vp
Dim SVp
Dim Twch
Dim VpgVpd
Dim Top
Dim Bottom
Dim SVpW
Dim N
Dim WCTF
Dim WCWSMPH
Public BattV
Public Windr
Public Temp
Public Vocht
Public Windskm
Public Rain_mmPublic BP_mbar
Public BP_mbar_Change
Public Temp_Change
Public Vocht_Change
Public SlrW
Public SlrkJ
Public Tot24
Public Windskn
Public Beaufort
Public AvgBeaufort
Public MaxBeaufort
Public Windroos As String
Public Windrichting As String
Public Beaufortnaam As String
Public Windsms
Public SinWindr
Public CosWindr
Public AvgSinWindr
Public AvgCosWindr
Public AvgWindr
Public SunHrs
Public PotSlrW
Public RTime(9)
Public SolPos(5)
Public TdC
Public TwC
Public WR_m
Public TotWR_m
Public TotSunHrs
Public WC_C
Public TotSun_H, TotSun_M, TotSun_S
Public TotSun_HMS As String * 32
Alias RTime(1)=Year
Alias RTime(2)=Month
Alias RTime(3)=DayOfMonth
Alias RTime(4)=HourOfDay
Alias RTime(5)=Minutes
Alias RTime(6)=Seconds
Alias RTime(7)=Microseconds
Alias RTime(8)=DayOfWeek
Alias RTime(9)=DayOfYear
Alias SolPos(1)=SolarAzimuth
Alias SolPos(2)=SunElevation
Alias SolPos(3)=HourAngle
Alias SolPos(4)=Declination
Alias SolPos(5)=AirMassUnits SunHrs=hours
Units BattV=Volts
Units Windr=Deg
Units Temp=DegC
Units Vocht=%
Units Windskm=kph
Units Windskn=kts
Units Rain_mm=mmUnits BP_mbar=mbar
Units Windsms=m/s
Units SlrW=W/m^2
Units SlrkJ=kJ/m^2
Units Windroos=String
Units Windrichting=String
Units Beaufortnaam=String
Units PotSlrW=W/m^2
Units TdC=Deg C
Units TwC=Deg C
Units WR_m=meters
Units WC_C=Deg C
Units Year=years
Units Month=months
Units DayOfMonth=days
Units HourOfDay=hours
Units Minutes=minutes
Units Seconds=seconds
Units Microseconds=microseconds
Units DayOfWeek=days
Units DayOfYear=days
Units SolarAzimuth=degrees
Units SunElevation=degrees
Units HourAngle=radians
Units Declination=radians
Units AirMass=unitless'Define Data TablesDataTable(TableOneMin,True,-1)
DataInterval(0,1,min,0)
WindVector (1,Windskm,Windr,IEEE4,False,0,0,1)
FieldNames ("Windskm,Windr")
Sample(1,Windroos,String)
FieldNames ("Windroos")
Maximum(1,Windskm,IEEE4,False,True)
FieldNames ("MaxWindskm")
SampleMaxMin (1,Windr,IEEE4,False)
Average(1,Temp,IEEE4,False)
FieldNames ("Temp")
Maximum(1,Temp,IEEE4,False,True)
FieldNames ("MaxTemp")
Minimum(1,Temp,IEEE4,False,True)
FieldNames ("MinTemp")
Average(1,Vocht,IEEE4,False)
FieldNames ("Vocht")
Maximum(1,Vocht,IEEE4,False,True)
FieldNames ("MaxVocht")
Minimum(1,Vocht,IEEE4,False,True)
FieldNames ("MinVocht")
Average(1,SlrW,IEEE4,False)
FieldNames ("SlrW")
Maximum(1,SlrW,IEEE4,False,True)
FieldNames ("MaxSlrW")
Totalize(1,SunHrs,IEEE4,False)
Average(1,Windsms,IEEE4,False)
FieldNames ("Windsms")
Maximum(1,Windsms,IEEE4,False,True)
FieldNames ("MaxWindsms")
Sample(1,TdC,IEEE4)
Sample(1,TwC,IEEE4)
Totalize(1,WR_m,IEEE4,False)
Sample(1,WC_C,IEEE4)
Average(1,Windskn,IEEE4,False)
FieldNames ("Windskn")
Maximum(1,Windskn,IEEE4,False,True)
FieldNames ("MaxWindskn")
Sample (1,AvgBeaufort,IEEE4)
FieldNames ("Beaufort")
Maximum (1,Beaufort,IEEE4,False,True)
FieldNames ("MaxBeaufort")
Average(1,BP_mbar,IEEE4,False)
FieldNames ("Baro")
Sample(1,Tot24,IEEE4)
FieldNames ("Tot24")
Sample(1,TotSun_HMS,String)
FieldNames ("TotSunHrs")
Sample(1,PotSlrW,IEEE4)
FieldNames ("PotSlrW")
Average(1,TdC,IEEE4,False)
FieldNames ("Dauw")
Maximum(1,TdC,IEEE4,False,True)
FieldNames ("MaxDauw")
Minimum(1,TdC,IEEE4,False,True)
FieldNames ("MinDauw")
Average(1,TwC,IEEE4,False)
FieldNames ("Nattebol")
Maximum(1,TwC,IEEE4,False,True)
FieldNames ("MaxNattebol")
Minimum(1,TwC,IEEE4,False,True)
FieldNames ("MinNattebol")EndTableDataTable(TableTenMin,True,-1)
DataInterval(0,10,min,0)
WindVector (1,Windskm,Windr,IEEE4,False,0,0,1)
FieldNames ("Windskm,Windr")
Sample(1,Windroos,String)
FieldNames ("Windroos")
Maximum(1,Windskm,IEEE4,False,True)
FieldNames ("MaxWindskm")
SampleMaxMin (1,Windr,IEEE4,False)
Average(1,Temp,IEEE4,False)
FieldNames ("Temp")
Maximum(1,Temp,IEEE4,False,True)
FieldNames ("MaxTemp")
Minimum(1,Temp,IEEE4,False,True)
FieldNames ("MinTemp")
Average(1,Vocht,IEEE4,False)
FieldNames ("Vocht")
Maximum(1,Vocht,IEEE4,False,True)
FieldNames ("MaxVocht")
Minimum(1,Vocht,IEEE4,False,True)
FieldNames ("MinVocht")
Average(1,SlrW,IEEE4,False)
FieldNames ("SlrW")
Average(1,Windsms,IEEE4,False)
FieldNames ("Windsms")
Maximum(1,Windsms,IEEE4,False,True)
FieldNames ("MaxWindsms")
Average(1,Windskn,IEEE4,False)
FieldNames ("Windskn")
Maximum(1,Windskn,IEEE4,False,True)
FieldNames ("MaxWindskn")
Sample (1,AvgBeaufort,IEEE4)
FieldNames ("Beaufort")
Maximum (1,Beaufort,IEEE4,False,True)
FieldNames ("MaxBeaufort")
Average(1,BP_mbar,IEEE4,False)
FieldNames ("Baro")
Sample(1,Tot24,IEEE4)
FieldNames ("Tot24")
Sample(1,TotSun_HMS,String)
FieldNames ("TotSunHrs")
EndTable
DataTable (Test,True,0)
DataInterval (0,1,Sec,0)
Sample (1,BP_mbar,IEEE4)
Sample (1,BP_mbar_Change,IEEE4)
EndTableDataTable (TestTemp,True,0)
DataInterval (0,1,Sec,0)
Sample (1,Temp,IEEE4)
Sample (1,Temp_Change,IEEE4)
EndTableDataTable (TestVocht,True,0)
DataInterval (0,1,Sec,0)
Sample (1,Vocht,IEEE4)
Sample (1,Vocht_Change,IEEE4)
EndTable'Main Program
BeginProg
Scan(1,Sec,1,0)'Default Datalogger Battery Voltage measurement BattV
Battery(BattV)
'Generic 4-20 mA Input measurement Windr
VoltDiff(Windr,1,mV2500,2,True,0,_60Hz,0.18,0)
'Generic 4-20 mA Input measurement Temp
VoltDiff(Temp,1,mV2500,3,True,0,_60Hz,0.05,-65)
'Generic 4-20 mA Input measurement Vocht
VoltDiff(Vocht,1,mV2500,4,True,0,_60Hz,0.05,-25)
'Generic 4-20 mA Input measurement Windskm
VoltDiff(Windskm,1,mV2500,1,True,0,_60Hz,0.081035,-39.9875)
'Generic Tipping Bucket Rain Gauge measurement Rain_mm
PulseCount(Rain_mm,1,1,2,0,0.2,0)
'PTB101B Barometric Pressure Sensor (CSL) measurement BP_mbar
VoltDiff(BP_mbar,1,mV2500,6,1,0,_60Hz,0.184,600)
'CM3 Pyranometer (CSL) measurements SlrkJ and SlrW
VoltDiff(SlrW,1,mV250,7,True,0,_60Hz,1,0)
'User Entered Calculation
Windr = (Windr-220+360)MOD 360
If Windr>360 Then Windr =Windr-360
If Windr <0 Then Windr = Windr+360
If Windr>=360 Then Windr=0If SlrW<0 Then SlrW=0
SlrkJ=SlrW*0.04330879
SlrW=SlrW*43.30879
'Calculate Sunshine Hours
'Get current time
RealTime(RTime(1))
'Calculate solar position
SolarPosition(SolPos(),RTime(),2*3600,51.483169,3.622959,0,BP_mbar,Temp)
'Calculate potential radiation for time && position (multiply sine of solar elevation angle by solar constant 1373)
PotSlrW=SIN(SunElevation)*1000
'If the measured value (W/m^2) is greater than 0.4 * the potential solar radiation (W/m^2)
'and the sine of the sun elevation angle (degrees) is great than 0.1 (elevation angle of 6 degrees)
'than it has been sunny for the current scan.
If SlrW>0.8*PotSlrW AND SIN(SunElevation)>0.1 Then
'Calculate sun hours for scan time in seconds
SunHrs=1/3600*1
Else
'Set sun hours for scan time in seconds to 0
SunHrs=0
If PotSlrW<0 Then PotSlrW=0
EndIf
'Dew Point and Wet-Bulb calculation prep
AirTC_2=Temp
SPkPa=101.325
SatVP(SVp,AirTC_2)
Vp=Vocht*SVp/100
'Dew Point calculation 'TdC'
DewPoint(TdC,AirTC_2,Vocht)
If TdC>AirTC_2 Or TdC=NAN Then TdC=AirTC_2
'Find Wet-Bulb 'TwC'
Top=AirTC_2
Bottom=TdC
For N = 1 To 25
Twpg=Twg
Twg=((Top-Bottom)/2)+Bottom
WetDryBulb(Vpg,AirTC_2,Twg,SPkPa)
VpgVpd=Vpg-Vp
Twch=ABS(Twpg-Twg)
If VpgVpd>0 Then
Top=Twg
Else
Bottom=Twg
EndIf
If Twch<0.01 Or N=25 Then ExitFor
Next
TwC=Twg
'Wind Run calculation 'WS'
'Convert to meters per second if needed and multiply by the scan rate in seconds
WR_m=Windskm/3.6
'Wind Chill calculation 'WC_C'
WCTF=1.8*Temp+32
WCWSMPH=Windskm*0.621371
WC_C=35.74+0.6215*WCTF-35.75*WCWSMPH^0.16+0.4275*WCTF*WCWSMPH^0.16
If WC_C>WCTF Or WC_C=NAN Then WC_C=WCTF
If WCTF>50 Or WCWSMPH<3 Then WC_C=WCTF
WC_C=(5/9)*(WC_C-32) '24 hour running total calculation Tot24
Tot24=Tot24+Rain_mm
If IfTime(0,1440,Min) Then Tot24=0
'24 hour running total calculation TotWR_m
TotWR_m=TotWR_m+WR_m
If IfTime(0,1440,Min) Then TotWR_m=0
'24 hour running total calculation TotSunHrs
TotSunHrs=TotSunHrs+SunHrs
If IfTime(0,1440,Min) Then TotSunHrs=0
TotSun_H=INT(TotSunHrs*24)
TotSun_M=INT((TotSunHrs*24-TotSun_H)*60)
TotSun_S=Round((((TotSunHrs*24-TotSun_H)*60)-TotSun_M)*60,0)
TotSun_HMS=FormatFloat(TotSun_H,"%02.00f")+":"+FormatFloat(TotSun_M,"%02.00f")+":"+FormatFloat(TotSun_S,"%02.00f")'Calculate 1 Minute Running Average For Wind Direction
SinWindr = SIN(Windr)
CosWindr = COS(Windr)
AvgRun (AvgSinWindr,1,SinWindr,60)
AvgRun (AvgCosWindr,1,CosWindr,60)
AvgWindr = ATN(AvgSinWindr/AvgCosWindr)
If AvgCosWindr < 0 Then
AvgWindr = 180 + AvgWindr
ElseIf AvgSinWindr < 0 Then
AvgWindr = 360 + AvgWindr
EndIf
'PTB101B Barometric Pressure Sensor (CSL) measurement BP_mbar
VoltDiff(BP_mbar,1,mV2500,6,1,0,_50Hz,0.184,600)
PortSet(1,0)
If Test.Record(1,1) > 0 Then
'calculate change for one hour
BP_mbar_Change = BP_mbar - Test.BP_mbar(1,1)
EndIf
'Generic 4-20 mA Input measurement Temp
VoltDiff(Temp,1,mV2500,3,True,0,_60Hz,0.05,-65)
PortSet(1,0)
If TestTemp.Record(1,1) > 0 Then
'calculate change for one hour
Temp_Change = Temp - TestTemp.Temp(1,1)
EndIf'Generic 4-20 mA Input measurement Vocht
VoltDiff(Vocht,1,mV2500,4,True,0,_60Hz,0.05,-25)
PortSet(1,0)
If TestVocht.Record(1,1) > 0 Then
'calculate change for one hour
Vocht_Change = Vocht - TestVocht.Vocht(1,1)
EndIf
'User Entered Calculation
If AvgWindr >= 348.75 AND AvgWindr <= 359.9 OR AvgWindr >= 0 AND AvgWindr <= 11.25 Then
Windroos = "N"
ElseIf AvgWindr > 11.25 AND AvgWindr < 33.25 Then
Windroos = "NNO"
ElseIf AvgWindr > 33.25 AND AvgWindr < 56.25 Then
Windroos = "NO"
ElseIf AvgWindr > 56.25 AND AvgWindr < 78.75 Then
Windroos = "ONO"
ElseIf AvgWindr > 78.75 AND AvgWindr < 101.25 Then
Windroos = "O"
ElseIf AvgWindr > 101.25 AND AvgWindr < 123.75 Then
Windroos = "OZO"
ElseIf AvgWindr > 123.75 AND AvgWindr < 146.25 Then
Windroos = "ZO"
ElseIf AvgWindr > 146.25 AND AvgWindr < 168.75 Then
Windroos = "ZZO"
ElseIf AvgWindr > 168.75 AND AvgWindr < 191.25 Then
Windroos = "Z"
ElseIf AvgWindr > 191.25 AND AvgWindr < 213.75 Then
Windroos = "ZZW"
ElseIf AvgWindr > 213.75 AND AvgWindr < 236.25 Then
Windroos = "ZW"
ElseIf AvgWindr > 236.25 AND AvgWindr < 258.75 Then
Windroos = "WZW"
ElseIf AvgWindr > 258.75 AND AvgWindr < 281.25 Then
Windroos = "W"
ElseIf AvgWindr > 281.25 AND AvgWindr < 303.75 Then
Windroos = "WNW"
ElseIf AvgWindr > 303.75 AND AvgWindr < 326.25 Then
Windroos = "NW"
ElseIf AvgWindr >= 326.25 AND AvgWindr <= 348.75 Then
Windroos = "NNW"
EndIf
'User Entered CalculationIf Windr >= 348.75 AND Windr <= 359.9 OR Windr >= 0 AND Windr <= 11.25 Then
Windrichting = "N"
ElseIf Windr > 11.25 AND Windr < 33.25 Then
Windrichting = "NNO"
ElseIf Windr > 33.25 AND Windr < 56.25 Then
Windrichting = "NO"
ElseIf Windr > 56.25 AND Windr < 78.75 Then
Windrichting = "ONO"
ElseIf Windr > 78.75 AND Windr < 101.25 Then
Windrichting = "O"
ElseIf Windr > 101.25 AND Windr < 123.75 Then
Windrichting = "OZO"
ElseIf Windr > 123.75 AND Windr < 146.25 Then
Windrichting = "ZO"
ElseIf Windr > 146.25 AND Windr < 168.75 Then
Windrichting = "ZZO"
ElseIf Windr > 168.75 AND Windr < 191.25 Then
Windrichting = "Z"
ElseIf Windr > 191.25 AND Windr < 213.75 Then
Windrichting = "ZZW"
ElseIf Windr > 213.75 AND Windr < 236.25 Then
Windrichting = "ZW"
ElseIf Windr > 236.25 AND Windr < 258.75 Then
Windrichting = "WZW"
ElseIf Windr > 258.75 AND Windr < 281.25 Then
Windrichting = "W"
ElseIf Windr > 281.25 AND Windr < 303.75 Then
Windrichting = "WNW"
ElseIf Windr > 303.75 AND Windr < 326.25 Then
Windrichting = "NW"
ElseIf Windr > 326.25 AND Windr < 348.75 Then
Windrichting = "NNW"
EndIf'User Entered Calculation
If Windskm<1 Then
Beaufortnaam = "Stil"
ElseIf Windskm<6 Then
Beaufortnaam = "Zwak"
ElseIf Windskm<12 Then
Beaufortnaam = "zwak"
ElseIf Windskm<20 Then
Beaufortnaam = "Matig"
ElseIf Windskm<29 Then
Beaufortnaam = "Matig"
ElseIf Windskm<39 Then
Beaufortnaam = "Vrij krachtig"
ElseIf Windskm<50 Then
Beaufortnaam = "Krachtig"
ElseIf Windskm<62 Then
Beaufortnaam = "Hard"
ElseIf Windskm<75 Then
Beaufortnaam = "Stormachtig"
ElseIf Windskm<89 Then
Beaufortnaam = "Storm"
ElseIf Windskm<103 Then
Beaufortnaam = "Zware storm"
ElseIf Windskm<117 Then
Beaufortnaam = "Zeer zware storm"
ElseIf Windskm>117 Then
Beaufortnaam = "Orkaan"
EndIf'User Entered CalculationWindskn=(Windskm/1.852)
Windsms=(Windskm/3.6)
If Windskm<1 Then
Beaufort=0
ElseIf Windskm<6 Then
Beaufort=1
ElseIf Windskm<12 Then
Beaufort=2
ElseIf Windskm<20 Then
Beaufort=3
ElseIf Windskm<29 Then
Beaufort=4
ElseIf Windskm<39 Then
Beaufort=5
ElseIf Windskm<50 Then
Beaufort=6
ElseIf Windskm<62 Then
Beaufort=7
ElseIf Windskm<75 Then
Beaufort=8
ElseIf Windskm<89 Then
Beaufort=9
ElseIf Windskm<103 Then
Beaufort=10
ElseIf Windskm<117 Then
Beaufort=11
ElseIf Windskm>117 Then
Beaufort=12
EndIfAvgRun (AvgBeaufort,1,Beaufort,600)
AvgBeaufort = Round (AvgBeaufort,0)
If AvgBeaufort > MaxBeaufort Then MaxBeaufort = AvgBeaufort
CallTable(TableOneMin)
CallTable(TableTenMin)
CallTable (Test)
CallTable (TestTemp)
CallTable (TestVocht)
NextScan
EndProg
Hi Mark,
I think it's nothing to do with new codes I given. I doubt there is an error in your orignial SunHrs calculation, it shoud be as follows:
Sunhrs = (1/86400)*1 'Not "Sunhrs = 1/3600*1" as per your origonal code, since your scan interval is 1 second.
Plsease change, yuor Sunhrs calculation as I sugested then, it should be fine. Please let me know if it works.
Regards,
Thein
Yes, That solved it.
Thanks alot Thein.