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.

Yearly Reset; dealing with leap day


Clayton Feb 8, 2012 12:01 AM

Hello,
I would like to be able to reset an annual precip total measurement on October 1st on a CR10X (multi-element timestamp uses DOY). Is there a way to use a nested if statement combined with a P92 "If Time Is" instruction (or some other technique) that would not be thrown off by the leap day? I'm guessing it will require a modulo divide (perhaps with p18) but I'm not sure how to code it and what the value to divide by would be. nSecPerYear*4?

Thanks,
Alex Clayton


ChipsNSalsa Feb 8, 2012 01:04 AM

I've taken the easy way out and used Edlogs built in expression compiler to do leap year calculations a few times. These should give you some ideas.

Here's one for calculating the day of the week that takes into account leap years:

;This program will calculate the day of the week from year and day of year.
;Sun=0, Mon=1, Tue=2, Wed=3, Thu=4, Fri=5, and Sat=6.

1: Do (P86)
1: 10 Set Output Flag High (Flag 0)

2: Set Active Storage Area (P80)
1: 3 Input Storage Area
2: 1 Loc [ YEAR ]

3: Real Time (P77)
1: 1111 Year,Day,Hour/Minute,Seconds (midnight = 0000)

DOFWK=(INT((YEAR-1)*365+((YEAR-1)/4)-((YEAR-1)/100)+((YEAR-1)/400))+DAY)@7


And here's one that calculates a Microsoft floating point date and takes into account leap years:

1: Do (P86)
1: 10 Set Output Flag High (Flag 0)

2: Set Active Storage Area (P80)
1: 3 Input Storage Area
2: 1 Loc [ YEAR ]

3: Real Time (P77)
1: 1111 Year,Day,Hour/Minute,Seconds (midnight = 0000)

EXCELDATE=(YEAR-1)*365+INT((YEAR-1)/4)-INT((YEAR-1)/100)+INT((YEAR-1)/400)+DAY-693594


Clayton Feb 9, 2012 04:28 PM

You can use expressions in Edlog?! Excellent, that's the first I've heard of it! Planning for a datalogger to be in service until 2100 might be a bit optimistic, but that expression certainly looks thorough. Thanks for the help.


ChipsNSalsa Feb 10, 2012 06:27 PM

Here you go. Rather than checking the hour and minute in the reset logic I used a flag to confirm for the rest of the day that the total had been reset. That makes it quite immune from the scan rate and skipped scans.

When doing a yearly total in an input location, don't forget to take advantage of the Edlog Options menu Power Up Settings and Compile Settings to "Retain Ports, Flags, User Timer, Input storage, and Intermediate storage".

;{CR10X}
*Table 1 Program
01: 1.0000 Execution Interval (seconds)

; Program to reset a precipitation total
; once a year on Oct 1 even on leap years.

1: Pulse (P3)
1: 1 Reps
2: 1 Pulse Channel 1
3: 2 Switch Closure, All Counts
4: 10 Loc [ Rain_mm ]
5: 0.254 Multiplier
6: 0.0 Offset

2: Z=X+Y (P33)
1: 9 X Loc [ YrTot_mm ]
2: 10 Y Loc [ Rain_mm ]
3: 9 Z Loc [ YrTot_mm ]

3: Do (P86)
1: 10 Set Output Flag High (Flag 0)

4: Set Active Storage Area (P80)
1: 3 Input Storage Area
2: 1 Loc [ Yr ]

5: Real Time (P77)^26672
1: 1111 Year,Day,Hour/Minute,Seconds (midnight = 0000)

6: Z=X MOD F (P46)
1: 1 X Loc [ Yr ]
2: 4 F
3: 5 Z Loc [ Mod4 ]

7: Z=X MOD F (P46)
1: 1 X Loc [ Yr ]
2: 100 F
3: 6 Z Loc [ Mod100 ]

8: Z=X MOD F (P46)
1: 1 X Loc [ Yr ]
2: 400 F
3: 7 Z Loc [ Mod400 ]

9: If (X<=>F) (P89)
1: 5 X Loc [ Mod4 ]
2: 1 =
3: 0 F
4: 30 Then Do

10: Z=F x 10^n (P30)
1: 275 F
2: 0 n, Exponent of 10
3: 8 Z Loc [ Oct1JD ]

11: If (X<=>F) (P89)
1: 6 X Loc [ Mod100 ]
2: 1 =
3: 0 F
4: 30 Then Do

12: Z=F x 10^n (P30)
1: 274 F
2: 0 n, Exponent of 10
3: 8 Z Loc [ Oct1JD ]

13: If (X<=>F) (P89)
1: 7 X Loc [ Mod400 ]
2: 1 =
3: 0 F
4: 30 Then Do

14: Z=F x 10^n (P30)
1: 274 F
2: 0 n, Exponent of 10
3: 8 Z Loc [ Oct1JD ]

15: End (P95)

16: End (P95)

17: End (P95)

18: If (X<=>Y) (P88)
1: 2 X Loc [ JD ]
2: 1 =
3: 8 Y Loc [ Oct1JD ]
4: 30 Then Do

19: If Flag/Port (P91)
1: 21 Do if Flag 1 is Low
2: 30 Then Do

20: Z=F x 10^n (P30)
1: 0 F
2: 0 n, Exponent of 10
3: 9 Z Loc [ YrTot_mm ]

21: Do (P86)
1: 11 Set Flag 1 High

22: End (P95)

23: Else (P94)

24: Do (P86)
1: 21 Set Flag 1 Low

25: End (P95)

*Table 2 Program
01: 0 Execution Interval (seconds)

*Table 3 Subroutines

End Program


ChipsNSalsa Feb 10, 2012 06:48 PM

Yes the Mod100 and Mod400 are major overkill for the next 88 and 388 years respectively, but they were applicable for Y2K and I came up with this stuff before then.

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