HP Forums
(34S )- Sunrise/Sunset version II - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (34S )- Sunrise/Sunset version II (/thread-3062.html)



(34S )- Sunrise/Sunset version II - Dieter - 02-11-2015 09:42 PM

The following WP34s program is a modified version of the one posted by Jeff O. a few days ago. It uses less memory registers and takes advantage of various 34s features, e.g. the date functions and inline integers. The output is different from Jeff's version, now all three results are displayed simultaneously.

The calculation is the same as in Jeff's version - I do not know much about all this, so I did not change the mathematics. Only some prestored constants (15, 18, 360, 24 etc.) were replaced with inline integers. Register use could be reduced significantly so that now R00 to R13 are all what's required. The number of registers might be reduced even further, but I did not want to change the calculation itself.

I added a routine to automatically adjust the output for daylight savings time. It assumes the rules within the European Union, i.e. DST starts on last Sunday in March and ends on last Sunday in October. If a date falls within this period flag A is set and the "=" annunciator comes on.

The mentioned rule is valid since 1996. The routine does not check for earlier dates and assumes the same rules for any year. If you do not want to include DST simply
omit steps 4 to 6. You may even completely ignore time zones and use UTC by setting the timezone offset in R03 to 0. If you live outside the EU you may code your own DST routine. It just has to set flag A if the date falls within the DST period (and CF A otherwise).

For more details please see Jeff's remarks on his program version. Registers 1 to 4 store some parameters you should personalize in the program code. Instead of the sample position (Frankfurt/Main, Germany) you should insert your local position (R01 and R02). Also the definition for sunrise/sunset (angle relative to zenith) can be adjusted (now 90°50').

Finally, here is the code:

Code:
LBL"SUN"    
STOM 00   Save mode settings in R00
DEG    
STO 05    Save entered date
XEQ"DST"  Check for daylight savings time
RCL 05    Omit these three steps if you want to set DST manually (SF A)
ENTER
YEAR
DEC X
#012
#031
→DATE     Create 31 Dec of previous year
ΔDAYS
+/-
STO 05    Save day of year
9
0
,
5         Set sunrise/sunset = 90°50' from zenith
0    
→HR       Convert to decimal degrees (90,83333)
STO 04
1         Set timezone relative to UTC, here CET = UTC+1
FS? A     DST?
INC X     then add 1 hour
STO 03
8         Set position,
,         here: Frankfurt/Main, Germany
4         Longitude = 8°41' East (positive, West = negative)
1
→HR       Convert to decimal degrees (8,683333)
STO 02
5
0
,
0         Latitude = 50° 7' North (positive, South = negative)
7
→HR       Convert to decimal degrees (50,116666)
STO 01
RCL 02
#015
/
STO 07
#018
XEQ 05
XEQ 06    Calculate sunset
STO 06
#006
XEQ 05
#180
STO+X
x<>Y
-
XEQ 06    Calculate sunrise
RCL 06
FIX 02    Set output format
RDX .     to hh.mm
CLα
αRC# Y    Sunrise
α"  "     two spaces
αRC# X    Sunset
RCL X
RCL Z
H.MS-     Day length
VWα+X
RCLM 00   Restore mode settings
RTN
LBL 05
RCL-07
#024
/
RCL+05
STO 08
,
9
8
5
6
x
3
,
2
8
9
-
STO 09
SIN
1
,
9
1
6
x
RCL+09
2
RCLx09
SIN
#050
/
+
3
RCLx09
SIN
3
SDR 004
x
+
2
8
2
,
6
3
4
+
#180
STO+X
MOD
STO 10
TAN
,
9
1
7
6
4
x
ATAN
#180
STO+X
MOD
STO 11
RCL 10
#090
/
FLOOR
#090
x
+
RCL 11
#090
/
FLOOR
#090
x
-
#015
/
STO 11
RCL 10
SIN
,
3
9
7
8
2
x
STO 12
ASIN
COS
STO 13
RCL 04
COS
RCL 01
SIN
RCLx12
-
RCL 01
COS
RCLx13
/
ACOS
RTN
LBL 06
#015
/
RCL+11
,
0
6
5
7
1
RCLx08
-
6
,
6    
2    
2    
-    
#024    
MOD    
RCL-07    
RCL+03    
→H.MS    
RTN
    
LBL"DST"  Checks for DST
STO 05
YEAR
FILL
#011      Determine last Sunday before 1 November
XEQ 01
x<>Y
#004      Determine last Sunday before 1 April
XEQ 01
RCL 05
D→J
SF A      Set Flag A (assume DST)
x≥? Y     IF date < 1st DST day
x≥? Z     OR date ≥ 1st day with standard time
CF A      THEN clear flag A
RTN
LBL 01
#001
→DATE     Create 1 April resp. 1 November
D→J
#007
IDIV
RCLxL     Monday on or before 1 April/November
DEC X     Last Sunday in March resp. October
RTN

Registers and flags:

Code:
Registers:
00 mode on startup
01 latitude in decimal degrees
02 longitude in decimal degrees
03 timezone relative to UTC
04 sunrise/sunset from zenith
05 date, day of year
06 time of sunset
07 - 13 are used internally

Flags: If Flag A is set, DST is assumed (timezone + 1 hour)

Usage: Enter a date (in the current date format), and XEQ"SUN" returns the time of sunrise, sunset and the day length. The "=" annunciator signals that DST is assumed.

The following example assumes d.my mode. If a different date mode is set, simply enter the date accordingly.

Code:
11,022015 XEQ"SUN"

=>     7.44  17.36    // sunrise and sunset
              9.52    // day length

04,072014 XEQ"SUN"

=>     5.21  21.37 =  // sunrise and sunset (DST)
             16.16    // day length

I did not do any comprehensive tests, so the program may contain errors. As usual, any corrections, suggestions and comments are welcome.

Dieter


RE: WP 34S - Sunrise/Sunset version II - Jeff O. - 02-13-2015 12:14 AM

Nice work Dieter.
I have been working on my program too and will soon post a new version incorporating some improvements you used, like inline integers, plus a version of your DST code modified for the conventions used in the US and Canada.