I am reading a wind sensor for direction and speed 1 time per second. With this 1 second data rate, I understand how to create a table and use WindVector to get the average direction, average speed and wind direction standard deviation over a period of time. The problem is the period of time I need is 2 minutes BUT I need that once per minute. If I set the period for 2 minutes, I only get output once every 2 minutes rather than one every minute. So I need the WindVector output as a 2 minute running average every 1 minute. Along the same general idea, I need the 10 minute maximum speed as a running average every 10 minutes.
I can achieve the 2 minute average speed with the AvgRun function but I cannot use AvgRun to get the 2 minute direction and standard deviation.
Weatherguy,
Were you able to get this figured out? If not, a possible solution would be to create two different datatables with different data intervals:
DataTable (Test1,1,-1)
DataInterval (0,2,min,10)
WindVector (1,WSpeed,WDir,FP2,False,0,0,0)
EndTable
DataTable (Test2,2,-1)
DataInterval (1,2,min,10)
WindVector (1,WSpeed,WDir,FP2,False,0,0,0)
EndTable
If you need the data in a single table, then you could conditionally pull the values from these tables (using the tablename.fieldname syntax) and assign them to associated variables. If you create a third table, you would have these variables sampled.
Program Example:
Public PTemp, batt_volt,wdir, wspeed
Public onemin_ws, onemin_wd, onemin_std
'Declare Other Variables
'Example:
'Dim Counter
'Define Data Tables.
DataTable (Test1,1,10)
DataInterval (0,2,min,10)
WindVector (1,wspeed,wdir,FP2,False,0,0,0)
EndTable
DataTable (Test2,1,10)
DataInterval (1,2,min,10)
WindVector (1,wspeed,wdir,FP2,False,0,0,0)
EndTable
DataTable (combined,1,-1)
DataInterval (0,1,min,10)
Sample (1,onemin_ws,FP2)
Sample (1,onemin_wd,FP2)
Sample (1,onemin_std,FP2)
EndTable
'Define Subroutines
'Sub
'EnterSub instructions here
'EndSub
'Main Program
BeginProg
Scan (1,Sec,0,0)
PanelTemp (PTemp,250)
Battery (batt_volt)
CallTable Test1
CallTable Test2
If IfTime(0,2,min)
onemin_ws = Test1.wspeed_WVc(1,1)
onemin_wd = Test1.wspeed_WVc(2,1)
onemin_std = Test1.wspeed_WVc(3,1)
EndIf
If IfTime(1,2,min)
onemin_ws = Test2.wspeed_WVc(1,1)
onemin_wd = Test2.wspeed_WVc(2,1)
onemin_std = Test2.wspeed_WVc(3,1)
EndIf
CallTable Combined
NextScan
EndProg
Uplander,
I had programmed it the 'brute force way' by breaking the dir and speed into components and using tables along with RunAvg. I also logged 1 second dir and speed plus wind components and used them to manually verify my CR1000 program. The problem is that my program results don't match up with the code you provided. It's close but not quite as close as I think it should be. I just need some time to go back and manually process some more 1 second winds and reverify everything. It may just be differences in the internal processing of the WindVector function versus my 'brute force way' code. I'd prefer to use your suggestion as it is more elegant and more efficient. I'm relatively new to datalogger programming and, while I had thought about programmatic table data access, my idea was different than your 1 table based on 2 others method and would have required more code. Very slick indeed!
As you have discovered, there are multiple ways to accomplish the same results - some are more involved than others. If you do try the approach I listed and you have additional questions, I would be happy to do what I can to answer.