Hello All,
I wrote a short CR200X program to test whether my programming for a rolling 24-hour accumulated rainfall would work. We report data every 15-minutes so a days worth of data would be from the last 96 samples. I used a For-Next loop and the TableName.FieldName function to pull the data from the last 96 arrays. However, my Rain_24HR variable is always NAN so here is a copy of my code below and thanks for any help!
Larry Treadaway - University of Florida
Public batt_volt
Public Rain_in
Public Rain_24HR
Dim R
Units Rain_in=inches
Units Rain_24HR=inches
'Define Data Tables.
DataTable (Test,1,-1) 'Set table size to # of records, or -1 to autoallocate.
DataInterval (0,15,Min)
Minimum (1,batt_volt,False,0)
Totalize (1,Rain_in,0)
EndTable
DataTable (Rainfall_24Hour,True,-1)
DataInterval (0,15,Min)
Sample (1,Rain_24HR)
EndTable
'Define Subroutines
Sub (Rain_24HR_Cal)
Rain_24HR=0
For R = 1 To 96
Rain_24HR=Test.Rain_in_tot(1,R)+Rain_24HR
Next R
EndSub
'Main Program
BeginProg
Scan (15,Sec)
Battery (batt_volt)
PulseCount (Rain_in,P_SW,2,0,0.01,0)
CallTable Test
Call Rain_24HR_Cal
CallTable Rainfall_24Hour
NextScan
EndProg
If you add NAN into a total, the total will be NAN.
If you try to access a record that doesn't exist, it will return NAN. My guess is that you didn't have 24 hours of data in your 15 minute table yet.
Thanks JDavis, much appreciated!
Larry
For anyone else wanting to do a 24-hour running total, it is supported in ShortCut in the Calculations & Control folder.
Thanks jra, unfortunately the ShortCut method does not do a 'true' running total, it resets the total at some time during the day. You can pick your time but still not what I would call a 'running total'. I am trying to get the datalogger to calculate the rainfall for the last 24 hours for each data array and do not want the total since midnight or whatever time. I think JDavis has the right idea so will do a test to see.
Regards,
Larry
The above program example works! Once you get the required number of arrays the NAN goes away and you get a running total of the last 24-hours. Thanks again to JDavis for the insight, very much appreciated.
Regards,
Larry
Newer data logger OS's support an easier instruction.
NOTE: THIS IS NOT SUPPORTED IN THE CR200Series DATA LOGGERS!
Try TotalRun instruction for this.
Here is an example used with a CR300 data logger. Note 1440 minutes in 24 hours, scan rate is 1 minute in this example program:
BeginProg
Scan (1,Min,0,0)
PulseCount(Rain_in,1,P_SW,2,0,0.01,0)
TotalRun (Rain24HourRun,1,Rain_in,1440)
In this example, Rain24HourRun would show the running rain total for 24 hours updated every minute.
I found the total run semi useful, tidy code, but had the same problem as the original post with a true running tally.
I did it slightly differently. So with this method I have a running last 24 hours total, plus can also see in real time upon which hour the event(s) happen. In the following example I had two gauges, one under an irrigator and one as rain. This allows me a real time quick view logging in remotely to the logger.
'CR800 Series Datalogger 'AshleyDene 'AD Trench '======================= 'program author: NDB 'Date 2020/05/21 'Name: 'ADT_pb92.CR8 '======================= ' Rain gauges(2), Rain and Trench Irrigation ' 2 * Pronamic Rain gauges tipping spoon ' Both model DK-8600 'rainIrr = 100.53/adj 1.00mm 'rain = Serial no. P4219/2008 adj 0.20mm item no. 300.023-20 '4 * CS616 Moisture sensors 'CS107 Temperature '======================= '------------------------------------------------------ ' Sensors and datalogger connections '------------------------------------------------------ 'Diff1 H SE1 <== 1 - CS616 'Diff1 L SE2 <== 2 - CS616 ' RG <== '----------------- 'Diff2 H SE3 <== 3 - CS616 'Diff2 L SE4 <== 4 - CS616 ' RG <== '---------------- 'Diff3 H SE5 <== 'Diff3 H SE6 <== Therm 107 Temp ' RG <==Therm 107 Temp '---------------- ' EX1 ==> Therm 107 Temp ' RG <== ' EX2 ==> ' RG <== ' P1 <== rain DK-8600 (adj 0.20mm) item no. 300.023-20) ' RG <== ' P2 <== irrg DK-8600 100.53/adj 1.00mm '---------------- ' G ==> ' 5v ==> '---------------- 'SW12 ==> ' G ==> '----------------SDM ' 12v ==> ' G ==> ' Tx C1 <==> ' Rx C2 <==> ' Tx C3 <==> '----------------SDM ' Rx C4 <==> CS616 Signal ' G ==> '-------------------------------------------------------- 'Declare Variables and Units PreserveVariables 'Dim num Public BattV As Float Public PTemp As Float Public soilTemp As Float Public TempCorrIO As Boolean = false Public vw(4) As Float Public vwt(4) As Float Public VWc(4) As Float Public rTime(9) As Float Alias rTime(4) = Hour Dim t Public rain As Float Public rainIrr As Float Public rainhr(24) As Float Public rainIrrhr(24) As Float Public rain24 As Float Public rainIrr24 As Float 'Define Data Tables DataTable(Hourly,True,-1) DataInterval(0,1,Hr,10) Average (1,BattV,FP2,False) Totalize (1,rain,FP2,False) Totalize (1,rainIrr,FP2,False) Average(1,soilTemp,FP2,False) Average(4,VWc(),FP2,False) Average(4,vw(),FP2,False) EndTable DataTable(Daily,True,-1) DataInterval(23,24,Hr,10) Maximum (1,BattV,FP2,False,False) Minimum (1,BattV,FP2,False,False) Totalize (1,rain,FP2,False) Totalize (1,rainIrr,FP2,False) Average(1,soilTemp,FP2,False) Average(4,VWc(),FP2,False) Maximum (1,soilTemp,FP2,False,False) Minimum (1,soilTemp,FP2,False,False) Maximum (4,VWc(),FP2,False,False) Minimum (4,VWc(),FP2,False,False) EndTable 'Main Program BeginProg 'Main Scan Scan(1,Min,1,0) RealTime (rTime()) Battery(BattV) PanelTemp(PTemp,_50Hz) Therm107(soilTemp,1,6,1,0,_50Hz,1,0) PulseCount (rain,1,1,2,0,0.2,0) PulseCount (rainIrr,1,2,2,0,1,0) 'Just for public viewing 'Each hour rain for 24 hours 'Note 24hr clock 0 to 23 'Note hour 1 = 0 to 1, Hour 24 = 23 to 24 If IfTime (0,60,Min) Then rainhr(Hour + 1) = 0 If IfTime (0,60,Min) Then rainIrrhr(Hour + 1) = 0 rainhr(Hour + 1) = rainhr(Hour + 1) + rain rainIrrhr(Hour + 1) = rainIrrhr(Hour + 1) + rainIrr rain24 = 0 rainIrr24 = 0 For t = 1 To 24 rain24 = rain24 + rainhr(t) rainIrr24 = rainIrr24 + rainIrrhr(t) Next t If IfTime (0,10,Min) Then'testing 1 minute, then 10min CS616 (vw(1),4,1,4,4,1.0,0) If ((10 <= soilTemp) AND (soilTemp <= 40)) Then If TempCorrIO = true Then vwt() = vw() + (20 - soilTemp) * (0.526 + vw() * (-0.052 + vw() * 0.00136)) Else vwt() = vw() EndIf Else vwt() = vw() EndIf VWc() = -0.0663 + vwt() * (-0.0063 + vwt() * 0.0007) EndIf 'Call Data Tables and Store Data CallTable Hourly CallTable Daily NextScan EndProg