Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Rounding an average.


Mavada Jan 29, 2011 09:25 PM

How to round to no decimals in the following instruction in a table.

Average (1,Beaufort,IEEE4,False)
FieldNames ("Beaufort")


IslandMan Jan 30, 2011 11:37 AM

Mavada,

I have fixed the program we have been working on together and it's below. Please read through it very carefully to spot all the corrections I have made. The program now rounds the Beaufort and Max Beaufort. Hopefully you have learned a few things from all this.
It would be a great idea for you to attend one of the great training sessions that Campbell Scientific has to offer in your region.

'CR1000
'Created by Short Cut (2.8)

'define all angles in degrees not radians
AngleDegrees

'Declare Variables and Units
Public BattV
Public Windr
Public Temp
Public Vocht
Public Windskm
Public Rain_mm
Public BP_mbar
Public SlrW
Public SlrkJ
Public Tot24
Public Windskn
Public Beaufort
Public AvgBeaufort
Public MaxBeaufort
Public Windroos As String

Public SinWindr
Public CosWindr
Public AvgSinWindr
Public AvgCosWindr
Public AvgWindr

Units BattV=Volts
Units Windr=Deg
Units Temp=DegC
Units Vocht=%
Units Windskm=kph
Units Windskn=kts
Units Rain_mm=mm
Units BP_mbar=mbar
Units SlrW=W/m^2
Units SlrkJ=kJ/m^2

'Define Data Tables
DataTable(Table1,True,-1)
DataInterval(0,10,Min,10)
WindVector (1,Windskm,Windr,FP2,False,0,0,1)
FieldNames ("Windskm,Windr")
Sample(1,Windroos,String)
FieldNames ("Windroos")
Maximum(1,Windskm,FP2,False,True)
FieldNames ("MaxWindskm")
Average(1,Temp,FP2,False)
FieldNames ("Temp")
Maximum(1,Temp,FP2,False,True)
FieldNames ("MaxTemp")
Minimum(1,Temp,FP2,False,True)
FieldNames ("MinTemp")
Average(1,Vocht,FP2,False)
FieldNames ("Vocht")
Maximum(1,Vocht,FP2,False,True)
FieldNames ("MaxVocht")
Minimum(1,Vocht,FP2,False,True)
FieldNames ("MinVocht")
Average(1,SlrW,FP2,False)
FieldNames ("SlrW")
Average(1,Windskn,FP2,False)
FieldNames ("Windskn")
Sample(1,AvgBeaufort,FP2)
FieldNames ("Beaufort")
Sample(1,Beaufort,FP2)
FieldNames ("MaxBeaufort")
Sample(1,BP_mbar,FP2)
FieldNames ("BaroP")
EndTable

DataTable(Table2,True,-1)
DataInterval(0,1,Min,10)
Minimum(1,BattV,FP2,False,False)
Sample(1,BP_mbar,FP2)
Sample(1,Windr,FP2)
Sample(1,SlrW,FP2)
Sample(1,Windskn,FP2)
Sample(1,Vocht,FP2)
Sample(1,Temp,FP2)
EndTable

'DataTable(Table3,True,-1)
'DataInterval(0,1,sec,10)
'Sample(1,BP_mbar,FP2)
'Sample(1,Windr,FP2)
'Sample(1,Temp,FP2)
'Sample(1,SlrW,FP2)
'Sample(1,Windskn,FP2)
'Sample(1,Windskm,FP2)
'Sample(1,Beaufort,FP2)
'Sample(1,Tot24,FP2)
'Sample(1,Vocht,FP2)
'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,_50Hz,0.18,-89.1)
'Generic 4-20 mA Input measurement Temp
VoltDiff(Temp,1,mV2500,3,True,0,_50Hz,0.05,-65)
'Generic 4-20 mA Input measurement Vocht
VoltDiff(Vocht,1,mV2500,4,True,0,_50Hz,0.05,-25)
'Generic 4-20 mA Input measurement Windskm
VoltDiff(Windskm,1,mV2500,1,True,0,_50Hz,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
PortSet(1,1)
VoltSe(BP_mbar,1,mV2500,11,1,0,_50Hz,0.184,600)
BP_mbar=BP_mbar*1
'CM3 Pyranometer (CSL) measurements SlrkJ and SlrW
VoltDiff(SlrW,1,mV250,7,True,0,_50Hz,1,0)
If SlrW<0 Then SlrW=0
SlrkJ=SlrW*0.04330879
SlrW=SlrW*43.30879

'24 hour running total calculation Tot24
Tot24=Tot24+Rain_mm
If IfTime(24,1440,Min) Then Tot24=0

'User Entered Calculation
Windr = Windr + 200
If Windr > 360 Then Windr = Windr - 360
If Windr < 0 Then Windr = Windr + 360
If Windr>=360 Then Windr=0

'Calculate 10 Minute Running average for Wind Direction
SinWindr = SIN(Windr)
CosWindr = COS(Windr)
AvgRun (AvgSinWindr,1,SinWindr,600)
AvgRun (AvgCosWindr,1,CosWindr,600)

AvgWindr = ATN(AvgSinWindr/AvgCosWindr)
If AvgCosWindr < 0 Then
AvgWindr = 180 + AvgWindr
ElseIf AvgSinWindr < 0 Then
AvgWindr = 360 + AvgWindr
EndIf

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 = "NNE"
ElseIf AvgWindr > 33.25 AND AvgWindr < 56.25 Then
Windroos = "NE"
ElseIf AvgWindr > 56.25 AND AvgWindr < 78.75 Then
Windroos = "ENE"
ElseIf AvgWindr > 78.75 AND AvgWindr < 101.25 Then
Windroos = "E"
ElseIf AvgWindr > 101.25 AND AvgWindr < 123.75 Then
Windroos = "ESE"
ElseIf AvgWindr > 123.75 AND AvgWindr < 146.25 Then
Windroos = "SE"
ElseIf AvgWindr > 146.25 AND AvgWindr < 168.75 Then
Windroos = "SSE"
ElseIf AvgWindr > 168.75 AND AvgWindr < 191.25 Then
Windroos = "S"
ElseIf AvgWindr > 191.25 AND AvgWindr < 213.75 Then
Windroos = "SSW"
ElseIf AvgWindr > 213.75 AND AvgWindr < 236.25 Then
Windroos = "SW"
ElseIf AvgWindr > 236.25 AND AvgWindr < 258.75 Then
Windroos = "WSW"
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 Calculation
Windskn=(Windskm/1.852)

'User Entered Calculation
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
EndIf

'Generate manual average for Beaufort
AvgRun (AvgBeaufort,1,Beaufort,600)
'Round the Average Beaufort to an Integer
AvgBeaufort = Round (AvgBeaufort,0)
'Calculate manual Max Beaufort
If AvgBeaufort > MaxBeaufort Then MaxBeaufort = AvgBeaufort
'Reset MaxBeaufort after 10 Minute table is written
If Table1.Output(1,1) Then MaxBeaufort = 0

'Call Data Tables and Store Data
CallTable(Table1)
CallTable(Table2)
'CallTable(Table3)
NextScan
EndProg


Mavada Jan 30, 2011 01:53 PM

Thanks again,

Ive changed the instruction for winddirection a bit because it didnt work.

Avg beaufort works great now!!!
The only thing that doesnt work is the public winddirection in n e s w. in the 10 min table it works great, but in realtime (public) it stay on NO, while it should often change to another direction...i think it keeps showing the avg winddirection...

'CR1000
'Created by Short Cut (2.8)
'define all angles in degrees not radians
AngleDegrees
'Declare Variables and Units
Public BattV
Public Windr
Public Temp
Public Vocht
Public Windskm
Public Rain_mm
Public BP_mbar
Public SlrW
Public SlrkJ
Public Tot24
Public Windskn
Public Beaufort
Public AvgBeaufort
Public MaxBeaufort
Public Windroos As String
Public SinWindr
Public CosWindr
Public AvgSinWindr
Public AvgCosWindr
Public AvgWindr
Units BattV=Volts
Units Windr=Deg
Units Temp=DegC
Units Vocht=%
Units Windskm=kph
Units Windskn=kts
Units Rain_mm=mm
Units BP_mbar=mbar
Units SlrW=W/m^2
Units SlrkJ=kJ/m^2
'Define Data Tables
DataTable(Table1,True,-1)
DataInterval(0,10,Min,10)
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")
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,Windskn,IEEE4,False)
FieldNames ("Windskn")
Maximum(1,Windskn,IEEE4,False,True)
FieldNames ("MaxWindskn")
Sample (1,AvgBeaufort,FP2)
FieldNames ("Beaufort")
Maximum (1,Beaufort,IEEE4,False,True)
FieldNames ("MaxBeaufort")
Sample(1,BP_mbar,IEEE4)
FieldNames ("BaroP")

EndTable
DataTable(Table2,True,-1)
DataInterval(0,1,Min,10)
Minimum(1,BattV,IEEE4,False,False)
Sample(1,BP_mbar,IEEE4)
Sample(1,Windr,IEEE4)
Sample(1,SlrW,IEEE4)
Sample(1,Windskn,IEEE4)
Sample(1,Vocht,IEEE4)
Sample(1,Temp,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,_50Hz,0.18,-89.1)
'Generic 4-20 mA Input measurement Temp
VoltDiff(Temp,1,mV2500,3,True,0,_50Hz,0.05,-65)
'Generic 4-20 mA Input measurement Vocht
VoltDiff(Vocht,1,mV2500,4,True,0,_50Hz,0.05,-25)
'Generic 4-20 mA Input measurement Windskm
VoltDiff(Windskm,1,mV2500,1,True,0,_50Hz,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
PortSet(1,1)
VoltSe(BP_mbar,1,mV2500,11,1,0,_50Hz,0.184,600)
BP_mbar=BP_mbar*1
'CM3 Pyranometer (CSL) measurements SlrkJ and SlrW
VoltDiff(SlrW,1,mV250,7,True,0,_50Hz,1,0)
If SlrW<0 Then SlrW=0
SlrkJ=SlrW*0.04330879
SlrW=SlrW*43.30879
'24 hour running total calculation Tot24
Tot24=Tot24+Rain_mm
If IfTime(24,1440,Min) Then Tot24=0
'User Entered Calculation
Windr = Windr + 200
If Windr > 360 Then Windr = Windr - 360
If Windr < 0 Then Windr = Windr + 360
If Windr>=360 Then Windr=0

'Calculate 10 Minute Running average for Wind Direction
SinWindr = SIN(Windr)
CosWindr = COS(Windr)
AvgRun (AvgSinWindr,1,SinWindr,600)
AvgRun (AvgCosWindr,1,CosWindr,600)
AvgWindr = ATN(AvgSinWindr/AvgCosWindr)
If AvgCosWindr < 0 Then
AvgWindr = 180 + AvgWindr
ElseIf AvgSinWindr < 0 Then
AvgWindr = 360 + AvgWindr
EndIf
If AvgWindr <= 11.25 Then
Windroos = "N"
ElseIf AvgWindr < 33.25 Then
Windroos = "NNO"
ElseIf AvgWindr < 56.25 Then
Windroos = "NO"
ElseIf AvgWindr < 78.75 Then
Windroos = "ONO"
ElseIf AvgWindr < 101.25 Then
Windroos = "O"
ElseIf AvgWindr < 123.75 Then
Windroos = "OZO"
ElseIf AvgWindr < 146.25 Then
Windroos = "ZO"
ElseIf AvgWindr < 168.75 Then
Windroos = "ZZO"
ElseIf AvgWindr < 191.25 Then
Windroos = "Z"
ElseIf AvgWindr < 213.75 Then
Windroos = "ZZW"
ElseIf AvgWindr < 236.25 Then
Windroos = "ZW"
ElseIf AvgWindr < 258.75 Then
Windroos = "WZW"
ElseIf AvgWindr < 281.25 Then
Windroos = "W"
ElseIf AvgWindr < 303.75 Then
Windroos = "WNW"
ElseIf AvgWindr < 326.25 Then
Windroos = "NW"
ElseIf AvgWindr < 348.75 Then
Windroos = "NNW"
EndIf

'User Entered Calculation
Windskn=(Windskm/1.852)
'User Entered Calculation
If Windskm<1 Then
'User Entered Calculation
Beaufort=0
'User Entered Calculation
ElseIf Windskm<6 Then
'User Entered Calculation
Beaufort=1
'User Entered Calculation
ElseIf Windskm<12 Then
'User Entered Calculation
Beaufort=2
'User Entered Calculation
ElseIf Windskm<20 Then
'User Entered Calculation
Beaufort=3
'User Entered Calculation
ElseIf Windskm<29 Then
'User Entered Calculation
Beaufort=4
'User Entered Calculation
ElseIf Windskm<39 Then
'User Entered Calculation
Beaufort=5
'User Entered Calculation
ElseIf Windskm<50 Then
'User Entered Calculation
Beaufort=6
'User Entered Calculation
ElseIf Windskm<62 Then
'User Entered Calculation
Beaufort=7
'User Entered Calculation
ElseIf Windskm<75 Then
'User Entered Calculation
Beaufort=8
'User Entered Calculation
ElseIf Windskm<89 Then
'User Entered Calculation
Beaufort=9
'User Entered Calculation
ElseIf Windskm<103 Then
'User Entered Calculation
Beaufort=10
'User Entered Calculation
ElseIf Windskm<117 Then
'User Entered Calculation
Beaufort=11
'User Entered Calculation
ElseIf Windskm>117 Then
'User Entered Calculation
Beaufort=12
'User Entered Calculation
EndIf
'Generate manual average for Beaufort
AvgRun (AvgBeaufort,1,Beaufort,600)
'Round the Average Beaufort to an Integer
AvgBeaufort = Round (AvgBeaufort,0)
'Calculate manual Max Beaufort
If AvgBeaufort > MaxBeaufort Then MaxBeaufort = AvgBeaufort 'Reset MaxBeaufort after 10 Minute table is written If Table1.Output(1,1) Then MaxBeaufort = 0

'Call Data Tables and Store Data
CallTable(Table1)
CallTable(Table2)

NextScan
EndProg

* Last updated by: Mavada on 1/30/2011 @ 6:54 AM *


IslandMan Feb 1, 2011 10:38 AM

1st, when referencing a problem, use the variable name from the program. Telling me windirection gives me no clue what you are talking about as there are multiple wind directions used in the program.

Did you actually load and run the test program I gave you for just this part of the program?

Think logically about what you have done.
You took the conditional statements I had with a range of wind direction and made them all single value statements.

If AvgWindr = 20, all of these statements would be TRUE.

ElseIf AvgWindr < 33.25 Then
Windroos = "NNO"
ElseIf AvgWindr < 56.25 Then
Windroos = "NO"
ElseIf AvgWindr < 78.75 Then
Windroos = "ONO"
ElseIf AvgWindr < 101.25 Then
Windroos = "O"
ElseIf AvgWindr < 123.75 Then
Windroos = "OZO"
ElseIf AvgWindr < 146.25 Then
Windroos = "ZO"
ElseIf AvgWindr < 168.75 Then
Windroos = "ZZO"
ElseIf AvgWindr < 191.25 Then
Windroos = "Z"
ElseIf AvgWindr < 213.75 Then
Windroos = "ZZW"
ElseIf AvgWindr < 236.25 Then
Windroos = "ZW"
ElseIf AvgWindr < 258.75 Then
Windroos = "WZW"
ElseIf AvgWindr < 281.25 Then
Windroos = "W"
ElseIf AvgWindr < 303.75 Then
Windroos = "WNW"
ElseIf AvgWindr < 326.25 Then
Windroos = "NW"
ElseIf AvgWindr < 348.75 Then
Windroos = "NNW"

I'm not sure why you don't use the program I gave you.
Once again, I suggest you see about getting some training on the Campbell Scientific loggers and software.

Log in or register to post/reply in the forum.