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.

Max gust and gustdirection last hour from one minut table.


Makada May 2, 2017 11:49 AM

Hi all,

Probably someone can shine a Light on this:

Id like to have the gust and gustdirection and time calculated from the last hour from a one minute table.

In other words,  every minute a max gust and gustdirection and corresponding time over the last immediate 60 samples is calculated. 

Maybe someone can show an example so i can use it in my program below. :

'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


Makada May 4, 2017 12:38 AM

Anyone please?


Makada May 4, 2017 06:30 PM

I came up with this, but the winddirection and time dont change according to the windgust calculated within the previous 540 data points. 

It only work when a new gust is recorded....

Public Windskm600(600)
Public Windskm
Public Windskm600Max(2), Windskm600Min(2)
Public Windr
Public WindrMax600
Public time_Windskm600Max_inst As String *100

'Main Program
BeginProg
Scan(1,Sec,1,0)

VoltDiff(Windskm,1,mV2500,1,True,0,_60Hz,0.081035,-39.9875)
VoltDiff(Windr,1,mV2500,2,True,0,_60Hz,0.18,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=0

Move (Windskm600(2),540,Windskm600(1),540)
Windskm600(1) = Windskm
MaxSpa (Windskm600Max,540,Windskm600(1))
MinSpa (Windskm600Min,540,Windskm600(1))
If Windskm=Windskm600Max Then
WindrMax600=Windr
time_Windskm600Max_inst=status.timestamp


EndIf
NextScan
EndProg


Makada May 5, 2017 02:12 PM

Hi all,

Anyone got an idea how to accomplish this?

Thanks in advance.

Mark.


Makada May 7, 2017 12:29 PM

Hi all,

ive added a table, but unfortunately still not working..

Someone willing to shine a light on this please...?

The maxspa function is working fine, but ik cant Get the 

Winddirection related to the maxspa function.

Public Windskm60(60)
Public Windskm
Public Windskm60Max(2), Windskm60Min(2)
Public Windr
Public Windr60 (60)

Public time_Windskm60Max_inst As String *100

'Define Data Tables

DataTable(TableOneSec,True,-1)
DataInterval(0,1,sec,0)
WindVector (1,Windskm,Windr,IEEE4,False,0,0,1)
FieldNames ("Windskm,Windr")
Maximum(1,Windskm60Max,IEEE4,False,True)
FieldNames ("MaxWindskm")
SampleMaxMin (1,Windr60,IEEE4,False)

EndTable

'Main Program

BeginProg
Scan(1,Sec,1,0)

VoltDiff(Windskm,1,mV2500,1,True,0,_60Hz,0.081035,-39.9875)
VoltDiff(Windr,1,mV2500,2,True,0,_60Hz,0.18,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=0

Move (Windskm60(2),59,Windskm60(1),59)
Windskm60(1) = Windskm
Move (Windr60(2),59,Windr60(1),59)
Windr60(1) = Windr

MaxSpa (Windskm60Max,59,Windskm60(1))
MinSpa (Windskm60Min,59,Windskm60(1))

time_Windskm60Max_inst=status.timestamp

CallTable (TableOneSec)NextScan
EndProg


Makada May 8, 2017 03:19 AM

Hi Andrew (aps),

Maybe youre willing/able to shine a light on this?

im struggling with it for days now...

im running the windspeed and winddirection in an array of lets say 60.

maxspa is running fine and updates fine when a gust is recorded and looks back in the previous 60 records for gusts when its on top of the 60 records.

but the gustdirection is the problem, it updates fine when a new gust is recorded, but it doesnt look back in the previous gust records and its related direction.

the program currently in use is shown above.

Thanks alot.

Mark


aps May 8, 2017 10:05 AM

I will have a look at this, but the reason the last program above does not work is that the datainternval in the datatable is set to be one second, so that means all the values max, mins etc will essentially be samples as you are calling the table once per sec and storing them once per sec.

One thing you will need to consider after I show you how to do what you need is to consider that the WMO definition of a gust is the 3 second average of wind, but that is easy to implement with avgrun.   If you want a 3 second average of direction to match that, it is a little more complicated.


aps May 8, 2017 10:50 AM

Try the program below which I think will do what you originally asked for.  I have not had time to load and test it thoroughly though, so it might need fine tuning.

'This is the one minute table
DataTable(TableOnemin,True,-1)
  DataInterval(0,1,min,10)
  WindVector (1,Windskm,Windr,IEEE4,False,0,0,1)
  FieldNames ("Windskm,Windr")
'Set the last parameter of the next instr true to capture time of max
  Maximum(1,Windskm,IEEE4,False,True)
  FieldNames ("MaxWindskm,Timeofmax")
  SampleMaxMin (1,Windr,IEEE4,False)
  FieldNames ("DiratMaxWindskm")
EndTable

'Main Program
BeginProg
  Scan(1,Sec,1,0)
    VoltDiff(Windskm,1,mV2500,1,True,0,_60Hz,0.081035,-39.9875)
    VoltDiff(Windr,1,mV2500,2,True,0,_60Hz,0.18,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=0
    CallTable (TableOnemin)
    'Only update the 60 minute max gust, direction and time once per
    'minute after the one minute table has stored data
    If tableonemin.output Then
      Move (Windskm60(2),59,Windskm60(1),59)
      Windskm60(1) = Tableonemin.MaxWindskm(1,1)
      Move (Windr60(2),59,Windr60(1),59)
      Windr60(1) = Tableonemin.DiratMaxWindskm(1,1)
      'Also use an array of times (as long integers)
      Move (Timeofmax60(2),59,Timeofmax60(1),59)
      Timeofmax60(1) = Tableonemin.Timeofmax(1,1)
      MaxSpa (Windskm60Max(),59,Windskm60(1))
      MinSpa (Windskm60Min(),59,Windskm60(1))
      'The MaxSpa second output points to the max value in the array
      'We use that value to pick out the matching direction and time
      'in the other two arrays of data
      Winddiratmaxs60=Windr60(Windskm60Max(2))
      Timeatmaxs60=Timeofmax60(Windskm60Max(2))
    EndIf
'Put any instructions to sample the new values here
'Be careful to sample the time values as type NSEC
  NextScan
EndProg


Makada May 8, 2017 11:29 AM

Hi Andrew,

Thanks alot for your input, much appreciated.

i got an error: line 45 variable Timeofmax60 out of bounds.

Any idea what is causing it?

With kind regards,

Mark. 

Public Windskm60(60)
Public Windskm
Public Windskm60Max(2), Windskm60Min(2)
Public Windr
Public Windr60 (60)
Public Windr60Max(2)
Public time_Windskm60Max_inst As String *100
Public Winddiratmaxs60
Public Timeofmax60(2) As Long
Public Timeatmax As Long
Public Timeofmax(60) As Long
Public Timeatmaxs60 As Long
'This is the one minute table
DataTable(TableOnemin,True,-1)
DataInterval(0,1,min,10)
WindVector (1,Windskm,Windr,IEEE4,False,0,0,1)
FieldNames ("Windskm,Windr")
'Set the last parameter of the next instr true to capture time of max
Maximum(1,Windskm,IEEE4,False,True)
FieldNames ("MaxWindskm,Timeofmax")
SampleMaxMin (1,Windr,IEEE4,False)
FieldNames ("DiratMaxWindskm")
Sample(1,Timeofmax,NSEC)
FieldNames ("TimeMax60")
EndTable'Main Program
BeginProg
Scan(1,Sec,1,0)
VoltDiff(Windskm,1,mV2500,1,True,0,_60Hz,0.081035,-39.9875)
VoltDiff(Windr,1,mV2500,2,True,0,_60Hz,0.18,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=0
CallTable (TableOnemin)
'Only update the 60 minute max gust, direction and time once per
'minute after the one minute table has stored data
If tableonemin.output Then
Move (Windskm60(2),59,Windskm60(1),59)
Windskm60(1) = Tableonemin.MaxWindskm(1,1)
Move (Windr60(2),59,Windr60(1),59)
Windr60(1) = Tableonemin.DiratMaxWindskm(1,1)
'Also use an array of times (as long integers)
Move (Timeofmax60(2),59,Timeofmax60(1),59)
Timeofmax60(1) = Tableonemin.Timemax60(1,1)
MaxSpa (Windskm60Max(),59,Windskm60(1))
MinSpa (Windskm60Min(),59,Windskm60(1))
'The MaxSpa second output points to the max value in the array
'We use that value to pick out the matching direction and time
'in the other two arrays of data
Winddiratmaxs60=Windr60(Windskm60Max(2))
Timeatmaxs60=Timeofmax60(Windskm60Max(2))
EndIf
'Put any instructions to sample the new values here
'Be careful to sample the time values as type NSEC
NextScan
EndProg


smh May 9, 2017 02:36 AM

deleted


aps May 9, 2017 03:39 AM

When I pasted in my example program above, I missed out the variable declarations by mistake.   You have recreated those declarations, but mixed up the names for arrays for holding the result of MaxSpa and the array of 60 minutes of values.

Below is the full program which seems to work.  I corrected one other bug in your original (see the MaxSpa) and added a test table too.

'Rearranged these variables to make them easier to check
Public Windskm
Public Windr

Public Windskm60Max(2)
Public Windskm60Min(2)
Public Winddiratmaxs60
Public Timeatmaxs60 As Long

'These could be redefined as DIMs,  post testing to save memory
Public Windskm60(60)
Public Windr60 (60)
Public Timeofmax60(60) As Long

'Define Data Tables
'First the one minute one
DataTable(TableOnemin,True,-1)
  DataInterval(0,1,min,10)
  WindVector (1,Windskm,Windr,IEEE4,False,0,0,1)
  FieldNames ("Windskm,Windr")
  'Set the last parameter of the next instr true to capture time of max
  Maximum(1,Windskm,IEEE4,False,True)
  FieldNames ("MaxWindskm,Timeofmax")
  SampleMaxMin (1,Windr,IEEE4,False)
  FieldNames ("DiratMaxWindskm")
EndTable

'Test of rolling max table

DataTable(rollingmaxtest,true,60)
  DataInterval(0,1,min,10)
  'Sample the 60 min rolling max ws, dir at max, and time of max
  Sample (1,Windskm60Max(),FP2)
  Sample (1,Winddiratmaxs60,FP2)
  Sample (1,Timeatmaxs60,Nsec)
EndTable


'Main Program
BeginProg
  Scan(1,Sec,1,0)
    VoltDiff(Windskm,1,mV2500,1,True,0,_60Hz,0.081035,-39.9875)
    VoltDiff(Windr,1,mV2500,2,True,0,_60Hz,0.18,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=0
    CallTable (TableOnemin)
    'Only update the 60 minute max gust, direction and time once per
    'minute after the one minute table has stored data
    If tableonemin.output Then
      Move (Windskm60(2),59,Windskm60(1),59)
      Windskm60(1) = Tableonemin.MaxWindskm(1,1)
      Move (Windr60(2),59,Windr60(1),59)
      Windr60(1) = Tableonemin.DiratMaxWindskm(1,1)
      'Also use an array of times (as long integers)
      Move (Timeofmax60(2),59,Timeofmax60(1),59)
      Timeofmax60(1) = Tableonemin.Timeofmax(1,1)
      'Look through all 60 values in the array (not 59)
      MaxSpa (Windskm60Max(),60,Windskm60(1))
      MinSpa (Windskm60Min(),60,Windskm60(1))
      'The MaxSpa second output points to the max value in the array
      'We use that value to pick out the matching direction and time
      'in the other two arrays of data
      Winddiratmaxs60=Windr60(Windskm60Max(2))
      Timeatmaxs60=Timeofmax60(Windskm60Max(2))
    EndIf
    'Put any instructions to sample the new values here
    'Be careful to sample the time values as type NSEC
    'e.g. this is a test table
    CallTable rollingmaxtest
  NextScan
EndProg


Makada May 9, 2017 04:02 AM

Thanks alot Andrew for Your input, i really couldnt achive this because of my lack of knowledge involving crbasic.

I will try your adjustments tonight when im home.

Thanks again,

Mark


Makada May 9, 2017 01:16 PM

Hi Andrew,

Its working flawless, very nice.

You mentioned the gust (and gust direction) calculation from the wmo.

Which i find out is a maximum 3 seconds average?

Didnt know that, can this be implemented in the code you provided?


aps May 10, 2017 02:46 AM

I added the 3s averaging of wind which is a minor change.   Whether you have a matching 3 sec averaged wind direction is a matter of personal preference and the WMO do not seem to recommend or specify that, so I have not bothered to put that in. 

Strictly speaking the WMO recommends the 3s gust windspeed measurement should be based upon 4 Hz measurements, but generally that makes little difference with most sensors, due to limitations in the sensors themselves or the scan rate of the program.

See below for the modified program:

'Rearranged the variables to make them easier to look at in monitors
Public Windskm, Windskm_3s
Public Windr

Public Windskm60Max(2)
Public Windskm60Min(2)
Public Winddiratmaxs60
Public Timeatmaxs60 As Long

'These could be redefined as DIMs post testing
Public Windskm60(60)
Public Windr60 (60)
Public Timeofmax60(60) As Long

'Define Data Tables
'First the one minute one
DataTable(TableOnemin,True,-1)
  DataInterval(0,1,min,10)
  WindVector (1,Windskm,Windr,IEEE4,False,0,0,1)
  FieldNames ("Windskm,Windr")
  'Set the last parameter of the next instr true to capture time of max
  'Capture the maximum 3 sec gust
  Maximum(1,Windskm_3s,IEEE4,False,True)
  FieldNames ("MaxWindskm_3s,Timeofmax")
  SampleMaxMin (1,Windr,IEEE4,False)
  FieldNames ("DiratMaxWindskm")
EndTable

DataTable(rollingmaxtest,true,60)
  DataInterval(0,1,min,10)
  'Sample the 60 min rolling max ws, dir at max, and time of max
  Sample (1,Windskm60Max(),FP2)
  Sample (1,Winddiratmaxs60,FP2)
  Sample (1,Timeatmaxs60,Nsec)
EndTable


'Main Program
BeginProg
  Scan(1,Sec,1,0)
    VoltDiff(Windskm,1,mV2500,1,True,0,_60Hz,0.081035,-39.9875)
    VoltDiff(Windr,1,mV2500,2,True,0,_60Hz,0.18,0)
    'Calc the 3s running average for gust estimation
    AvgRun(Windskm_3s,1,Windskm,3)
    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=0
    CallTable (TableOnemin)
    'Only update the 60 minute max gust, direction and time once per
    'minute after the one minute table has stored data
    If tableonemin.output Then
      Move (Windskm60(2),59,Windskm60(1),59)
      Windskm60(1) = Tableonemin.MaxWindskm_3s(1,1)
      Move (Windr60(2),59,Windr60(1),59)
      Windr60(1) = Tableonemin.DiratMaxWindskm(1,1)
      'Also use an array of times (as long integers)
      Move (Timeofmax60(2),59,Timeofmax60(1),59)
      Timeofmax60(1) = Tableonemin.Timeofmax(1,1)
      'Look through all 60 values in the array (not 59)
      MaxSpa (Windskm60Max(),60,Windskm60(1))
      MinSpa (Windskm60Min(),60,Windskm60(1))
      'The MaxSpa second output points to the max value in the array
      'We use that value to pick out the matching direction and time
      'in the other two arrays of data
      Winddiratmaxs60=Windr60(Windskm60Max(2))
      Timeatmaxs60=Timeofmax60(Windskm60Max(2))
    EndIf
    'Put any instructions to sample the new values here
    'Be careful to sample the time values as type NSEC
    'e.g. this is a test table
    CallTable rollingmaxtest
  NextScan
EndProg


Makada May 10, 2017 03:41 AM

Thanks Andrew, will try tonight.

With kind regards,

Mark


Makada May 10, 2017 02:11 PM

Hi Andrew,

Am i right only the 1sec max speed is used in the part below?

Could there be added the running 3sec max version to?

DataTable(rollingmaxtest,true,60)
  DataInterval(0,1,min,10)
  'Sample the 60 min rolling max ws, dir at max, and time of max
  Sample (1,Windskm60Max(),FP2)
  Sample (1,Winddiratmaxs60,FP2)
  Sample (1,Timeatmaxs60,Nsec)
EndTable

And i noticed when the rolling max 60 isnt changed for some time,  it looks for the gust winddirection. Thats changing every minute by looking for the greatest gustdirection value but the gust stays the same.

But thats maybe related because ive added the 1sec max, in the one minute table and the move section....


aps May 11, 2017 05:07 AM

The above does use the the 3s average wind speed because:

a) in the one minute table I use the windskm_3s value as input to the maximum instruction:

  'Set the last parameter of the next instr true to capture time of max
  'Capture the maximum 3 sec gust
  Maximum(1,Windskm_3s,IEEE4,False,True)
  FieldNames ("MaxWindskm_3s,Timeofmax")

b) the maximum value of the 3s average is then loaded into the Windskm60 array:

      Windskm60(1) = Tableonemin.MaxWindskm_3s(1,1)

With respect to your second point it is possible for the same maximum windspeed to be stored in the rollingmaxtest table but with a different direction, because when the program does the MaxSpa instruction this will return the position of the first maximum it finds in the array and that index is used to find the matching wind direction.   As new speeds are written into the start of the array it is possible that an identical but newer max speed is found and its matching direction could be different.


Makada May 12, 2017 04:02 AM

Hi Andrew,

Thanks alot for your input.

I tried to implement the 1sec data next to the 3sec data but couldnt get it to work.

And if i use the ''select case'' instruction for the winddirection shown in text, eg nne ssw etc, i know how to use it for one table, but can i use the same ''select case'' for multiple tables?

Or do i have to use the example below for every table apart?

Select Case Windr
 
Case Is >=0 AND Is <=11.25
WDtxt = "N"
Case Is >11.25 AND Is <=33.75
WDtxt = "NNO"
Case Is >33.75 AND Is <=56.25
WDtxt = "NO"
Case Is >56.25 AND Is <=78.75
WDtxt = "ONO"
Case Is >78.75 AND Is <=101.25
WDtxt = "O"
Case Is >101.25 AND Is <=123.75
WDtxt = "OZO"
Case Is >123.75 AND Is <=146.25
WDtxt = "ZO"
Case Is >146.25 AND Is <=168.75
WDtxt = "ZZO"
Case Is >168.75 AND Is <=191.25
WDtxt = "Z"
Case Is >191.25 AND Is <=213.75
WDtxt = "ZZW"
Case Is >213.75 AND Is <=236.25
WDtxt = "ZW"
Case Is >236.25 AND Is <=258.75
WDtxt = "WZW"
Case Is >258.75 AND Is <=281.25
WDtxt = "W"
 Case Is >281.25 AND Is <=303.75
WDtxt = "WNW"
Case Is >303.75 AND Is <=326.25
WDtxt = "NW"
Case Is >326.25 AND Is <=348.75
WDtxt = "NNW"
Case Is >348.75 AND Is <=360
WDtxt = "N"
EndSelect


aps May 12, 2017 08:50 AM

HAve you considered putting the code above in a subroutine which can be called multiple times?


Makada May 12, 2017 09:05 AM

like so?

Select Case Windr,Tableonemin.DiratMaxWindskm

that didnt work, i think it added up all the winddirection values.


Makada May 15, 2017 05:05 AM

Hi Andrew,

ive added the 60 min and 1440 min (day) data to it and the running average windspeed and running average direction (and the max average speed), but im kind of lost in my own input at the moment....

is it possible you have a look at it please?

With kind regards,

Mark 

'Rearranged these variables to make them easier to check
Public Windskm
Public Windr
Public Windskm60Max(2)
Public Windskm60Min(2)
Public Winddiratmaxs60
Public Timeatmaxs60 As Long
Public WDtxt As String * 5
Public WDtxt_2 As String * 5
Public WDtxt_3 As String * 5
Public WDtxt_4 As String * 5
Public WDtxt_5 As String * 5Public SinWindr
Public CosWindr
Public AvgSinWindr
Public AvgCosWindr
Public AvgWindrPublic Windskm10Avg
Public Windskm60Avg
Public Windskm10Max(2)
Public Windskm10Min(2)
Public Winddiratmaxs10
Public Timeatmaxs10 As Long
Public Windskm1440Max(2)
Public Windskm1440Min(2)
Public Winddiratmaxs1440
Public Timeatmaxs1440 As Long

'These could be redefined as DIMs,  post testing to save memory
Dim Windskm60(60)
Dim Windr60 (60)
Dim Timeofmax60(60) As Long
Dim Windskm10(10)
Dim Windr10 (10)
Dim Timeofmax10(10) As Long
Dim Windskm1440(1440)
Dim Windr1440 (1440)
Dim Timeofmax1440(1440) As Long'Define Data Tables

'First the one minute one
DataTable(TableOnemin,True,-1)
DataInterval(0,1,min,10)
WindVector (1,Windskm,Windr,IEEE4,False,0,0,1)
FieldNames ("Windskm,Windr")
'Set the last parameter of the next instr true to capture time of max
Maximum(1,Windskm,IEEE4,False,True)
FieldNames ("MaxWindskm,Timeofmax")
SampleMaxMin (1,Windr,IEEE4,False)
FieldNames ("DiratMaxWindskm")
Average(1,Windskm,IEEE4,False)
FieldNames ("WindskmAvg")
Average(1,Windr,IEEE4,False)
FieldNames ("WindrAvg")EndTable

'Test of rolling max table
DataTable(rollingmaxtest,true,60)
DataInterval(0,1,min,10)

'Sample the 60 min rolling max ws, dir at max, and time of max
Sample (1,Windskm60Max(),FP2)
Sample (1,Winddiratmaxs60,FP2)
Sample (1,Timeatmaxs60,Nsec)
Sample (1,Windskm60Avg,FP2)
EndTableDataTable(rollingmaxtest10,true,10)

DataInterval(0,1,min,10)
'Sample the 10 min rolling max ws, dir at max, and time of max
Sample (1,Windskm10Max(),FP2)
Sample (1,Winddiratmaxs10,FP2)
Sample (1,Timeatmaxs10,Nsec)
Sample (1,Windskm10Avg,FP2)
Sample (1,AvgWindr,FP2)EndTableDataTable(rollingmaxtest1440,true,1440)

DataInterval(0,1,min,10)
'Sample the 1440 min rolling max ws, dir at max, and time of max
Sample (1,Windskm1440Max(),FP2)
Sample (1,Winddiratmaxs1440,FP2)
Sample (1,Timeatmaxs1440,Nsec)

EndTable

'Main Program
BeginProg
Scan(1,Sec,1,0)
VoltDiff(Windskm,1,mV2500,1,True,0,_60Hz,0.081035,-39.9875)
VoltDiff(Windr,1,mV2500,2,True,0,_60Hz,0.18,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=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
EndIfCallTable (TableOnemin)

'Only update the 60 minute max gust, direction and time once per
'minute after the one minute table has stored data

If tableonemin.output Then
Move (Windskm60(2),59,Windskm60(1),59)
Windskm60(1) = Tableonemin.MaxWindskm(1,1)
Move (Windr60(2),59,Windr60(1),59)
Windr60(1) = Tableonemin.DiratMaxWindskm(1,1)

Move (Windskm10(2),9,Windskm10(1),9)
Windskm10(1) = Tableonemin.MaxWindskm(1,1)

Move (Windr10(2),9,Windr10(1),9)
Windr10(1) = Tableonemin.DiratMaxWindskm(1,1)

Move (Windskm1440(2),1439,Windskm1440(1),1439)
Windskm1440(1) = Tableonemin.MaxWindskm(1,1)
Move (Windr1440(2),1439,Windr1440(1),1439)
Windr1440(1) = Tableonemin.DiratMaxWindskm(1,1)

'Also use an array of times (as long integers)
Move (Timeofmax60(2),59,Timeofmax60(1),59)
Timeofmax60(1) = Tableonemin.Timeofmax(1,1)
'Look through all 60 values in the array (not 59)
MaxSpa (Windskm60Max(),60,Windskm60(1))
MinSpa (Windskm60Min(),60,Windskm60(1))
AvgSpa (Windskm60Avg(),60,Windskm60(1))

'The MaxSpa second output points to the max value in the array
'We use that value to pick out the matching direction and time
'in the other two arrays of data
Winddiratmaxs60=Windr60(Windskm60Max(2))
Timeatmaxs60=Timeofmax60(Windskm60Max(2))

'Also use an array of times (as long integers)
Move (Timeofmax10(2),9,Timeofmax10(1),9)
Timeofmax10(1) = Tableonemin.Timeofmax(1,1)
'Look through all 10 values in the array (not 59)
MaxSpa (Windskm10Max(),10,Windskm10(1))
MinSpa (Windskm10Min(),10,Windskm10(1))
AvgSpa (Windskm10Avg(),10,Windskm10(1))

'The MaxSpa second output points to the max value in the array
'We use that value to pick out the matching direction and time
'in the other two arrays of data
Winddiratmaxs10=Windr10(Windskm10Max(2))
Timeatmaxs10=Timeofmax10(Windskm10Max(2))

'Also use an array of times (as long integers)
Move (Timeofmax1440(2),1439,Timeofmax1440(1),1439)
Timeofmax1440(1) = Tableonemin.Timeofmax(1,1)

'Look through all 60 values in the array (not 59)
MaxSpa (Windskm1440Max(),1440,Windskm1440(1))
MinSpa (Windskm1440Min(),1440,Windskm1440(1))

'The MaxSpa second output points to the max value in the array
'We use that value to pick out the matching direction and time
'in the other two arrays of data
Winddiratmaxs1440=Windr1440(Windskm1440Max(2))
Timeatmaxs1440=Timeofmax1440(Windskm1440Max(2))

If IfTime(0,1440,Min) Then Windskm10Max=0
If IfTime(0,1440,Min) Then Winddiratmaxs10=0
If IfTime(0,1440,Min) Then Timeatmaxs10=0If IfTime(0,1440,Min) Then Windskm60Max=0
If IfTime(0,1440,Min) Then Winddiratmaxs60=0
If IfTime(0,1440,Min) Then Timeatmaxs60=0If IfTime(0,1440,Min) Then Windskm1440Max=0
If IfTime(0,1440,Min) Then Winddiratmaxs1440=0
If IfTime(0,1440,Min) Then Timeatmaxs1440=0EndIf
'Put any instructions to sample the new values here
'Be careful to sample the time values as type NSEC
'e.g. this is a test table
Select Case Windr
 
Case Is >=0 AND Is <=11.25
WDtxt = "N"
Case Is >11.25 AND Is <=33.75
WDtxt = "NNO"
Case Is >33.75 AND Is <=56.25
WDtxt = "NO"
Case Is >56.25 AND Is <=78.75
WDtxt = "ONO"
Case Is >78.75 AND Is <=101.25
WDtxt = "O"
Case Is >101.25 AND Is <=123.75
WDtxt = "OZO"
Case Is >123.75 AND Is <=146.25
WDtxt = "ZO"
Case Is >146.25 AND Is <=168.75
WDtxt = "ZZO"
Case Is >168.75 AND Is <=191.25
WDtxt = "Z"
Case Is >191.25 AND Is <=213.75
WDtxt = "ZZW"
Case Is >213.75 AND Is <=236.25
WDtxt = "ZW"
Case Is >236.25 AND Is <=258.75
WDtxt = "WZW"
Case Is >258.75 AND Is <=281.25
WDtxt = "W"
 Case Is >281.25 AND Is <=303.75
WDtxt = "WNW"
Case Is >303.75 AND Is <=326.25
WDtxt = "NW"
Case Is >326.25 AND Is <=348.75
WDtxt = "NNW"
Case Is >348.75 AND Is <=360
WDtxt = "N"
EndSelectSelect Case rollingmaxtest.Winddiratmaxs60
 
Case Is >=0 AND Is <=11.25
WDtxt_2 = "N"
Case Is >11.25 AND Is <=33.75
WDtxt_2 = "NNO"
Case Is >33.75 AND Is <=56.25
WDtxt_2 = "NO"
Case Is >56.25 AND Is <=78.75
WDtxt_2 = "ONO"
Case Is >78.75 AND Is <=101.25
WDtxt_2 = "O"
Case Is >101.25 AND Is <=123.75
WDtxt_2 = "OZO"
Case Is >123.75 AND Is <=146.25
WDtxt_2 = "ZO"
Case Is >146.25 AND Is <=168.75
WDtxt_2 = "ZZO"
Case Is >168.75 AND Is <=191.25
WDtxt_2 = "Z"
Case Is >191.25 AND Is <=213.75
WDtxt_2 = "ZZW"
Case Is >213.75 AND Is <=236.25
WDtxt_2 = "ZW"
Case Is >236.25 AND Is <=258.75
WDtxt_2 = "WZW"
Case Is >258.75 AND Is <=281.25
WDtxt_2 = "W"
 Case Is >281.25 AND Is <=303.75
WDtxt_2 = "WNW"
Case Is >303.75 AND Is <=326.25
WDtxt_2 = "NW"
Case Is >326.25 AND Is <=348.75
WDtxt_2 = "NNW"
Case Is >348.75 AND Is <=360
WDtxt_2 = "N"
EndSelect
Select Case Tableonemin.DiratMaxWindskm
 
Case Is >=0 AND Is <=11.25
WDtxt_3 = "N"
Case Is >11.25 AND Is <=33.75
WDtxt_3= "NNO"
Case Is >33.75 AND Is <=56.25
WDtxt_3 = "NO"
Case Is >56.25 AND Is <=78.75
WDtxt_3 = "ONO"
Case Is >78.75 AND Is <=101.25
WDtxt_3 = "O"
Case Is >101.25 AND Is <=123.75
WDtxt_3 = "OZO"
Case Is >123.75 AND Is <=146.25
WDtxt_3 = "ZO"
Case Is >146.25 AND Is <=168.75
WDtxt_3 = "ZZO"
Case Is >168.75 AND Is <=191.25
WDtxt_3 = "Z"
Case Is >191.25 AND Is <=213.75
WDtxt_3 = "ZZW"
Case Is >213.75 AND Is <=236.25
WDtxt_3 = "ZW"
Case Is >236.25 AND Is <=258.75
WDtxt_3 = "WZW"
Case Is >258.75 AND Is <=281.25
WDtxt_3 = "W"
 Case Is >281.25 AND Is <=303.75
WDtxt_3 = "WNW"
Case Is >303.75 AND Is <=326.25
WDtxt_3 = "NW"
Case Is >326.25 AND Is <=348.75
WDtxt_3 = "NNW"
Case Is >348.75 AND Is <=360
WDtxt_3 = "N"
EndSelectSelect Case rollingmaxtest10.Winddiratmaxs10
 
Case Is >=0 AND Is <=11.25
WDtxt_5 = "N"
Case Is >11.25 AND Is <=33.75
WDtxt_5 = "NNO"
Case Is >33.75 AND Is <=56.25
WDtxt_5 = "NO"
Case Is >56.25 AND Is <=78.75
WDtxt_5 = "ONO"
Case Is >78.75 AND Is <=101.25
WDtxt_5 = "O"
Case Is >101.25 AND Is <=123.75
WDtxt_5 = "OZO"
Case Is >123.75 AND Is <=146.25
WDtxt_5 = "ZO"
Case Is >146.25 AND Is <=168.75
WDtxt_5 = "ZZO"
Case Is >168.75 AND Is <=191.25
WDtxt_5 = "Z"
Case Is >191.25 AND Is <=213.75
WDtxt_5 = "ZZW"
Case Is >213.75 AND Is <=236.25
WDtxt_5 = "ZW"
Case Is >236.25 AND Is <=258.75
WDtxt_5 = "WZW"
Case Is >258.75 AND Is <=281.25
WDtxt_5 = "W"
 Case Is >281.25 AND Is <=303.75
WDtxt_5 = "WNW"
Case Is >303.75 AND Is <=326.25
WDtxt_5 = "NW"
Case Is >326.25 AND Is <=348.75
WDtxt_5 = "NNW"
Case Is >348.75 AND Is <=360
WDtxt_5 = "N"
EndSelectSelect Case rollingmaxtest1440.Winddiratmaxs1440
 
Case Is >=0 AND Is <=11.25
WDtxt_4 = "N"
Case Is >11.25 AND Is <=33.75
WDtxt_4 = "NNO"
Case Is >33.75 AND Is <=56.25
WDtxt_4 = "NO"
Case Is >56.25 AND Is <=78.75
WDtxt_4 = "ONO"
Case Is >78.75 AND Is <=101.25
WDtxt_4 = "O"
Case Is >101.25 AND Is <=123.75
WDtxt_4 = "OZO"
Case Is >123.75 AND Is <=146.25
WDtxt_4 = "ZO"
Case Is >146.25 AND Is <=168.75
WDtxt_4 = "ZZO"
Case Is >168.75 AND Is <=191.25
WDtxt_4 = "Z"
Case Is >191.25 AND Is <=213.75
WDtxt_4 = "ZZW"
Case Is >213.75 AND Is <=236.25
WDtxt_4 = "ZW"
Case Is >236.25 AND Is <=258.75
WDtxt_4 = "WZW"
Case Is >258.75 AND Is <=281.25
WDtxt_4 = "W"
 Case Is >281.25 AND Is <=303.75
WDtxt_4 = "WNW"
Case Is >303.75 AND Is <=326.25
WDtxt_4 = "NW"
Case Is >326.25 AND Is <=348.75
WDtxt_4 = "NNW"
Case Is >348.75 AND Is <=360
WDtxt_4 = "N"
EndSelectCallTable rollingmaxtest
CallTable rollingmaxtest10
CallTable rollingmaxtest1440
NextScan
EndProg


Makada May 16, 2017 11:35 PM

Hi Andrew,

I managed to get the avg windspeed and max avg windspeed working,

But only fot the 10 minute average.

When i want the max ten minute average last hour, im stuck...

...and the time of max avg windspeed doesnt work.

Could you have a look at what im doing wrong? (ive tried the 10min version first, so the 60 and 1440 minutes time of max avg arent used yet.)

'Rearranged these variables to make them easier to check
Public Windskm
Public Windr
'------------------------------------------
Public Windskm10Max(2)
Public Windskm10Min(2)
Public Winddiratmaxs10
Public Windskm10AvgMax(2)
Public Timeatmaxs10 As Long

'-------------------------------------------
Public Windskm60Max(2)
Public Windskm60Min(2)
Public Winddiratmaxs60
Public Windskm60Avg
Public Timeatmaxs60 As Long
'--------------------------------------------
Public Windskm1440Max(2)
Public Windskm1440Min(2)
Public Winddiratmaxs1440
Public Windskm1440Avg
Public Timeatmaxs1440 As Long
'---------------------------------------------
Public WDtxt As String * 5
Public WDtxt_2 As String * 5
Public WDtxt_3 As String * 5
Public WDtxt_4 As String * 5
'---------------------------------------------
Public TodaysWindskm10Max
Public TodaysWindskm60Max
Public TodaysWindskm1440Max

'These could be redefined as DIMs,  post testing to save memory
Dim Windskm10(10)
Dim Windr10 (10)
Dim Windskm10Avg (10)
Dim Timeofmax10(10) As Long
Dim Timeofmax10Avg(10) As Long
'-----------------------------------------------
Dim Windskm60(60)
Dim Windr60 (60)
Dim Timeofmax60(60) As Long
'-----------------------------------------------
Dim Windskm1440(1440)
Dim Windr1440 (1440)
Dim Timeofmax1440(1440) As Long
'------------------------------------------------
'Define Data Tables
'First the one minute one
DataTable(TableOnemin,True,-1)
DataInterval(0,1,min,10)
WindVector (1,Windskm,Windr,IEEE4,False,0,0,1)
FieldNames ("Windskm,Windr")
'Set the last parameter of the next instr true to capture time of max
Maximum(1,Windskm,IEEE4,False,True)
FieldNames ("MaxWindskm,Timeofmax")
SampleMaxMin (1,Windr,IEEE4,False)
FieldNames ("DiratMaxWindskm")
Maximum(1,Windskm10Avg,IEEE4,False,True)
FieldNames ("TimeofmaxAvg10")
EndTable
'---------------------------------------------------------------------
'Test of rolling max 10 table
DataTable(rollingmaxtest10,true,10)
DataInterval(0,1,min,10)
'Sample the 10 min rolling max ws, dir at max, and time of max
Sample (1,Windskm10Max(),FP2)
Sample (1,Winddiratmaxs10,FP2)
Sample (1,Timeatmaxs10,Nsec)
Sample (1,Timeofmax10Avg,Nsec)
Sample (1,Windskm10Avg(),FP2)
Sample (1,Windskm10AvgMax(),FP2)
EndTable
'----------------------------------------------------------------------
'Test of rolling max 60 table
DataTable(rollingmaxtest60,true,60)
DataInterval(0,1,min,10)
'Sample the 60 min rolling max ws, dir at max, and time of max
Sample (1,Windskm60Max(),FP2)
Sample (1,Winddiratmaxs60,FP2)
Sample (1,Timeatmaxs60,Nsec)
EndTable
'----------------------------------------------------------------------
'Test of rolling max 1440 table
DataTable(rollingmaxtest1440,true,1440)
DataInterval(0,1,min,10)
'Sample the 1440 min rolling max ws, dir at max, and time of max
Sample (1,Windskm1440Max(),FP2)
Sample (1,Winddiratmaxs1440,FP2)
Sample (1,Timeatmaxs1440,Nsec)
EndTable
'----------------------------------------------------------------------
'Main Program
BeginProg
Scan(1,Sec,1,0)
VoltDiff(Windskm,1,mV2500,1,True,0,_60Hz,0.081035,-39.9875)
VoltDiff(Windr,1,mV2500,2,True,0,_60Hz,0.18,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=0
CallTable (TableOnemin)
'----------------------------------------------------------------------
'Only update the 60 minute max gust, direction and time once per
'minute after the one minute table has stored data
If tableonemin.output Then
Move (Windskm60(2),59,Windskm60(1),59)
Windskm60(1) = Tableonemin.MaxWindskm(1,1)
Move (Windr60(2),59,Windr60(1),59)
Windr60(1) = Tableonemin.DiratMaxWindskm(1,1)
'Also use an array of times (as long integers)
Move (Timeofmax60(2),59,Timeofmax60(1),59)
Timeofmax60(1) = Tableonemin.Timeofmax(1,1)
'Look through all 60 values in the array (not 59)
MaxSpa (Windskm60Max(),60,Windskm60(1))
MinSpa (Windskm60Min(),60,Windskm60(1))
AvgSpa (Windskm60Avg(),60,Windskm60(1))
'The MaxSpa second output points to the max value in the array
'We use that value to pick out the matching direction and time
'in the other two arrays of data
Winddiratmaxs60=Windr60(Windskm60Max(2))
Timeatmaxs60=Timeofmax60(Windskm60Max(2))
EndIf
'Put any instructions to sample the new values here
'Be careful to sample the time values as type NSEC
'e.g. this is a test table
TodaysWindskm60Max=rollingmaxtest60.Windskm60Max
'-----------------------------------------------------------------------
'Only update the 10 minute max gust, direction and time once per
'minute after the one minute table has stored data
If tableonemin.output Then
Move (Windskm10(2),9,Windskm10(1),9)
Windskm10(1) = Tableonemin.MaxWindskm(1,1)
Move (Windr10(2),9,Windr10(1),9)
Windr10(1) = Tableonemin.DiratMaxWindskm(1,1)
Move (Windskm10Avg(2),9,Windskm10Avg(1),9)
Windskm10Avg(1) = Tableonemin.Windskm(1,1)
'Also use an array of times (as long integers)
Move (Timeofmax10(2),9,Timeofmax10(1),9)
Timeofmax10(1) = Tableonemin.Timeofmax(1,1)

Move (Timeofmax10Avg(2),9,Timeofmax10Avg(1),9)
Timeofmax10Avg(1) = Tableonemin.TimeofmaxAvg10(1,1)
'Look through all 10 values in the array (not 59)
MaxSpa (Windskm10Max(),10,Windskm10(1))
MinSpa (Windskm10Min(),10,Windskm10(1))
AvgSpa (Windskm10Avg(),10,Windskm10(1))
MaxSpa (Windskm10AvgMax(),10,Windskm10Avg(1))
'The MaxSpa second output points to the max value in the array
'We use that value to pick out the matching direction and time
'in the other two arrays of data
Winddiratmaxs10=Windr10(Windskm10Max(2))
Timeatmaxs10=Timeofmax10(Windskm10Max(2))
EndIf
'Put any instructions to sample the new values here
'Be careful to sample the time values as type NSEC
'e.g. this is a test table
TodaysWindskm10Max=rollingmaxtest10.Windskm10Max

'----------------------------------------------------------------------
'Only update the 1440 minute max gust, direction and time once per
'minute after the one minute table has stored data
If tableonemin.output Then
Move (Windskm1440(2),1439,Windskm1440(1),1439)
Windskm1440(1) = Tableonemin.MaxWindskm(1,1)
Move (Windr1440(2),1439,Windr1440(1),1439)
Windr1440(1) = Tableonemin.DiratMaxWindskm(1,1)
'Also use an array of times (as long integers)
Move (Timeofmax1440(2),1439,Timeofmax1440(1),1439)
Timeofmax1440(1) = Tableonemin.Timeofmax(1,1)
'Look through all 1440 values in the array (not 59)
MaxSpa (Windskm1440Max(),1440,Windskm1440(1))
MinSpa (Windskm1440Min(),1440,Windskm1440(1))
AvgSpa (Windskm1440Avg(),1440,Windskm1440(1))
'The MaxSpa second output points to the max value in the array
'We use that value to pick out the matching direction and time
'in the other two arrays of data
Winddiratmaxs1440=Windr1440(Windskm1440Max(2))
Timeatmaxs1440=Timeofmax1440(Windskm1440Max(2))
EndIf
'Put any instructions to sample the new values here
'Be careful to sample the time values as type NSEC
'e.g. this is a test table
TodaysWindskm1440Max=rollingmaxtest1440.Windskm1440Max
'---------------------------------------------------------------------
Select Case Windr
Case Is >=0 AND Is <=11.25
WDtxt = "N"
Case Is >11.25 AND Is <=33.75
WDtxt = "NNO"
Case Is >33.75 AND Is <=56.25
WDtxt = "NO"
Case Is >56.25 AND Is <=78.75
WDtxt = "ONO"
Case Is >78.75 AND Is <=101.25
WDtxt = "O"
Case Is >101.25 AND Is <=123.75
WDtxt = "OZO"
Case Is >123.75 AND Is <=146.25
WDtxt = "ZO"
Case Is >146.25 AND Is <=168.75
WDtxt = "ZZO"
Case Is >168.75 AND Is <=191.25
WDtxt = "Z"
Case Is >191.25 AND Is <=213.75
WDtxt = "ZZW"
Case Is >213.75 AND Is <=236.25
WDtxt = "ZW"
Case Is >236.25 AND Is <=258.75
WDtxt = "WZW"
Case Is >258.75 AND Is <=281.25
WDtxt = "W"
 Case Is >281.25 AND Is <=303.75
WDtxt = "WNW"
Case Is >303.75 AND Is <=326.25
WDtxt = "NW"
Case Is >326.25 AND Is <=348.75
WDtxt = "NNW"
Case Is >348.75 AND Is <=360
WDtxt = "N"
EndSelect
'---------------------------------------------------------------------
Select Case rollingmaxtest60.Winddiratmaxs60
Case Is >=0 AND Is <=11.25
WDtxt_2 = "N"
Case Is >11.25 AND Is <=33.75
WDtxt_2 = "NNO"
Case Is >33.75 AND Is <=56.25
WDtxt_2 = "NO"
Case Is >56.25 AND Is <=78.75
WDtxt_2 = "ONO"
Case Is >78.75 AND Is <=101.25
WDtxt_2 = "O"
Case Is >101.25 AND Is <=123.75
WDtxt_2 = "OZO"
Case Is >123.75 AND Is <=146.25
WDtxt_2 = "ZO"
Case Is >146.25 AND Is <=168.75
WDtxt_2 = "ZZO"
Case Is >168.75 AND Is <=191.25
WDtxt_2 = "Z"
Case Is >191.25 AND Is <=213.75
WDtxt_2 = "ZZW"
Case Is >213.75 AND Is <=236.25
WDtxt_2 = "ZW"
Case Is >236.25 AND Is <=258.75
WDtxt_2 = "WZW"
Case Is >258.75 AND Is <=281.25
WDtxt_2 = "W"
 Case Is >281.25 AND Is <=303.75
WDtxt_2 = "WNW"
Case Is >303.75 AND Is <=326.25
WDtxt_2 = "NW"
Case Is >326.25 AND Is <=348.75
WDtxt_2 = "NNW"
Case Is >348.75 AND Is <=360
WDtxt_2 = "N"
EndSelect
'----------------------------------------------------------------------
Select Case rollingmaxtest10.Winddiratmaxs10
Case Is >=0 AND Is <=11.25
WDtxt_3 = "N"
Case Is >11.25 AND Is <=33.75
WDtxt_3= "NNO"
Case Is >33.75 AND Is <=56.25
WDtxt_3 = "NO"
Case Is >56.25 AND Is <=78.75
WDtxt_3 = "ONO"
Case Is >78.75 AND Is <=101.25
WDtxt_3 = "O"
Case Is >101.25 AND Is <=123.75
WDtxt_3 = "OZO"
Case Is >123.75 AND Is <=146.25
WDtxt_3 = "ZO"
Case Is >146.25 AND Is <=168.75
WDtxt_3 = "ZZO"
Case Is >168.75 AND Is <=191.25
WDtxt_3 = "Z"
Case Is >191.25 AND Is <=213.75
WDtxt_3 = "ZZW"
Case Is >213.75 AND Is <=236.25
WDtxt_3 = "ZW"
Case Is >236.25 AND Is <=258.75
WDtxt_3 = "WZW"
Case Is >258.75 AND Is <=281.25
WDtxt_3 = "W"
 Case Is >281.25 AND Is <=303.75
WDtxt_3 = "WNW"
Case Is >303.75 AND Is <=326.25
WDtxt_3 = "NW"
Case Is >326.25 AND Is <=348.75
WDtxt_3 = "NNW"
Case Is >348.75 AND Is <=360
WDtxt_3 = "N"
EndSelect
'----------------------------------------------------------------------
Select Case rollingmaxtest1440.Winddiratmaxs1440
Case Is >=0 AND Is <=11.25
WDtxt_4 = "N"
Case Is >11.25 AND Is <=33.75
WDtxt_4 = "NNO"
Case Is >33.75 AND Is <=56.25
WDtxt_4 = "NO"
Case Is >56.25 AND Is <=78.75
WDtxt_4 = "ONO"
Case Is >78.75 AND Is <=101.25
WDtxt_4 = "O"
Case Is >101.25 AND Is <=123.75
WDtxt_4 = "OZO"
Case Is >123.75 AND Is <=146.25
WDtxt_4 = "ZO"
Case Is >146.25 AND Is <=168.75
WDtxt_4 = "ZZO"
Case Is >168.75 AND Is <=191.25
WDtxt_4 = "Z"
Case Is >191.25 AND Is <=213.75
WDtxt_4 = "ZZW"
Case Is >213.75 AND Is <=236.25
WDtxt_4 = "ZW"
Case Is >236.25 AND Is <=258.75
WDtxt_4 = "WZW"
Case Is >258.75 AND Is <=281.25
WDtxt_4 = "W"
 Case Is >281.25 AND Is <=303.75
WDtxt_4 = "WNW"
Case Is >303.75 AND Is <=326.25
WDtxt_4 = "NW"
Case Is >326.25 AND Is <=348.75
WDtxt_4 = "NNW"
Case Is >348.75 AND Is <=360
WDtxt_4 = "N"
EndSelect
'----------------------------------------------------------------------
CallTable rollingmaxtest60
CallTable rollingmaxtest10
CallTable rollingmaxtest1440
NextScan
EndProg


Makada Mar 3, 2019 12:46 PM

Hi Andrew,

The program above works great, but i would like to have some more functions added if possible:)

1. Id like to have the 3s average winddirection matching the 3s Max windgust.

2. Id like to have the average winddirection from a 10 min max average windspeed. (From one minute table).

With kind regards.

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