Post Reply 
(34S) - Sunrise/Sunset
01-28-2015, 08:08 PM (This post was last modified: 06-15-2017 01:29 PM by Gene.)
Post: #1
(34S) - Sunrise/Sunset
**Update No. 2**
Yet another version, this time with local registers and DST correction built in. (Thanks and credit to Dieter for the DST code.) DST settings are for the US, DST beginning on the second Sunday in March and ending on the first Sunday in November.

If you prefer manual DST, remove steps 4 through 22 and subroutine 01 which begins at step 224. You may then manually set flag A for DST. It will be cleared after each use - if you prefer to stay in DST mode for a series of calculations, change the "FS?C A" in step 34 to simply "FS? A."

If you don't want to use local registers, just remove the LocR16 command and the "." in front of each register number

Operation is essentially as described for the first versions. Here is a dat file for the emulator.
.zip  wp34s.zip (Size: 674 bytes / Downloads: 13)
(I removed the dat file below for the original version.)

Sunrise/Sunset Program:
Code:

Step    Instruction    Comments
001    LBL  'RS'      
002    LocR 016       allocate 16 local registers
003    DEG            Set degrees mode (used throughout)
004    STO .00        store input date
005    YEAR           get year of input date
006    FILL           fill stack
007    #011           enter 11, for November
008    XEQ 01         calculate j-day for last Sunday in October
009    #007           enter 7
010    +              add 7 for US DST end 1st Sunday in November
011    x<>Y           get year of input date back
012    #003           enter 3, for March
013    XEQ 01         calculate j-day for last Sunday in February
014    #014           enter 14
015    +              add 14 for US DST start 2nd Sunday in March
016    RCL .00        recall input date
017    D→J            get j-day of input date
018    SF A           set DST flag
019    x≥? Y          IF date < first DST day 
020    x≥? Z          OR date ≥ first standard time day
021    CF A           THEN clear DST flag
022    RCL .00        Recall input date
023    ENTER          Copy input date into Y, could use RCL X, etc.
024    YEAR           year of input date
025    DEC X          previous year
026    #12            enter 12
027    #31            enter 31
028    →DATE          create last day of previous year in current date mode.
029    X<>Y           
030    ΔDAYS          days from beginning of year
031    STO .04        
032    5              Offset from UTC (-5 represents EST)
033    +/-            Offset from UTC (-5 represents EST)
034    FS?C A         If flag A set, DST in effect for input date
035    INC X          If flag A set, increment offset from UTC
036    STO .03        Local time offset from UTC
037    9              
038    0              
039    .              
040    5              
041    ->HR           90.83333333333333 entered for degrees from zenith at
                      Sunrise/sunset (fewer steps than direct entry)
042    STO .05        degrees from zenith for Sunrise.  May be changed if
                      twilight times or other solar elevation times are desired (e.g.
                      enter 50 to find times when sun is at 40 degrees altitude.)
043    3              Latitude
044    5              Latitude
045    .              Latitude
046    1              Latitude
047    2              Latitude
048    3              Latitude
049    4              Latitude
050    5              Latitude
051    STO .01        35.12345 for example (decimal)
052    9              Longitude
053    0              Longitude
054    .              Longitude
055    5              Longitude
056    4              Longitude
057    3              Longitude
058    2              Longitude
059    1              Longitude
060    +/-            Longitude
061    STO .02        -90.54321 for example (decimal)
062    #015           15 Degrees per hour
063    STO .09        Store for later use
064    /              
065    STO .06        Longitude hour value (lngHour)
066    #018           
067    XEQ 05         Calculate approximate time for sunset
068    XEQ 06         
069    STO .13        Done calculating sunset.  Store the result
070    6              Calculate sunrise
071    XEQ 05         
072    RCL .14        Recall 360
073    RCL- Y         
074    XEQ 06         
075    RCL .13        Recall sunset.  Push sunrise to Y.
076    CL alpha       clear alpha register for new text message
077    'Ris'          
078    'e-S'          
079    'et'           
080    VIEWa          Display text
081    PSE 25         
082    CL alpha       clear alpha register for new text message
083    alphaRC# Y     copy Y register value to alpha register
084    VWalpha+ X     view alpha (sunrise) in dot-matrix, sunset time in X register.
085    STOP           
086    CPX STO Z      store sunrise and sunset times in Z and T
087    x<>Y           
088    H.MS-          subtract sunrise from sunset for day length
089    CL alpha       
090    'Day'          
091    ' Le'          
092    'ngt'          
093    'h'            
094    VWa+ X         Display text and day length
095    RTN            done
096    LBL 05         Subroutine for large common section
097    RCL- .06       
098    #024           enter 24
099    /              
100    RCL+ .04       
101    STO .07        Approximate sunset time
102    .              
103    9              
104    8              
105    5              
106    6              enter 0.9856
107    x              
108    3              
109    .              
110    2              
111    8              
112    9              enter 3.289
113    -              
114    STO .08        Sun's mean anomaly
115    SIN            Calculate sun's true longitude
116    1              
117    .              
118    9              
119    1              
120    6              enter 1.916
121    x              
122    RCL+ .08       
123    2              
124    RCLx .08       
125    SIN            
126    #002           
127    SDR 002        enter 0.02
128    x              
129    +              
130    3              
131    RCLx .08       
132    SIN            
133    3              
134    SDR 004        enter 0.0003
135    x              
136    +              
137    2              
138    8              
139    2              
140    .              
141    6              
142    3              
143    4              enter 282.634
144    +              
145    #36            
146    SDL 001        enter 360
147    STO .14        
148    MOD            
149    STO .08        Sun's true longitude
150    TAN            Calculate sun's Right Ascension
151    .              
152    9              
153    1              
154    7              
155    6              
156    4              enter 0.91764
157    x              
158    ATAN           
159    RCL .14        enter 360
160    MOD            
161    STO .10        Sun's Right Ascension
162    RCL .08        
163    #090           enter 90
164    STO .15        Store for later use
165    /              
166    FLOOR          
167    RCLx .15       Recall 90 and multiply
168    +              
169    RCL .10        
170    RCL/ .15       Recall 90 and divide
171    FLOOR          
172    RCLx .15       Recall 90 and multiply
173    -              
174    RCL/ .09       Recall 15 and divide
175    STO .10        Sun's Right Ascension converted into hours
176    RCL .08        
177    SIN            
178    .              
179    3              
180    9              
181    7              
182    8              
183    2              enter 0.39782
184    x              
185    STO .11        sinDec for sunset
186    ASIN           
187    COS            
188    STO .12        cosDec for sunset
189    RCL .05        
190    COS            
191    RCL .01        
192    SIN            
193    RCLx .11       
194    -              
195    RCL  .01       
196    COS            
197    RCLx .12       
198    /              Sun's local Hour Angle (cosH)
199    ACOS           
200    RTN            
201    LBL 06         Subroutine for another common section
202    RCL/ .09       Recall 15 and divide
203    RCL+ .10       
204    .              
205    0              
206    6              
207    5              
208    7              
209    1              enter 0.06571
210    RCLx .07       
211    -              
212    6              
213    .              
214    6              
215    2              
216    2              enter 6.622
217    -              
218    #024           enter 24
219    MOD            
220    RCL- .06       
221    RCL+ .03       
222    ->H.MS         
223    RTN            
224    LBL 01         Subroutine to calculate last Sunday of prior month.
225    #001           
226    →DATE           = 1 March resp. 1 November
227    D→J            
228    #007           
229    IDIV           
230    RCLx L          Monday on or before 1 March resp. 1 November
231    DEC X           last Sunday of February resp. October
232    END

Registers:
Code:

Register    Use/contents
.00    Input date
.01    latitude
.02    longitude
.03    Local time offset from UTC
.04    day number of year
.05    degrees from zenith for Sunrise.
.06    Longitude hour value (lngHour)
.07    Approximate sunset time
.08    Sun's mean anomaly/Sun's true longitude
.09    15 degrees per hour
.10    Sun's Right Ascension/right ascension converted to hours
.11    sinDec for sunset
.12    cosDec for sunset
.13    sunset time
.14    360
.15    90



**See below for an update**
Below are three versions of a program for the wp34s to calculate sunrise and sunset times. The programs are based on programs that I got from Marwan Joury, versions of which he posted in this article. I give total credit to Marwan, all I did was port his work to the wp34s. Most of the comments in my program listings are from Marwan's original listings that he sent to me. (So if you have any questions regarding the meat of the program, you will have to ask Marwan...)

Program operation is as follows:

Replace steps 6 and 7 with your offset from UTC, West is negative. (You must manually account for Daylight Saving Time, or British Summer Time, or whatever your local flavor of seasonally shifting daylight hours to suit local custom is called if you have one.)

Key in your latitude in steps 15 through 22 in decimal degrees, North is positive.

Key in your longitude in steps 24 through 32 in decimal degrees, West is negative. (You may use as many digits as you want for longitude and latitude, there is no requirement for 5 digits past the decimal point.)

Go to run mode, key in the date in which you are interested in yyyy.mmdd format for version 1, dd.mmyyyy format for version 2 or mm.ddyyyy format for version 3. Press XEQ 'RS'. The program will run, briefly display "Rise-Set", then stop with the sunrise time displayed in the dot-matrix display area, and the sunset time displayed in the numerical display, in 24 hour clock format. Press R/S if you want see the day length. The sunrise and sunset times will still be on the stack in Z and Y, respectively, if you want to look at them again. All returned values are in hh.mmss format.

Since your location information is hard-coded into the program, after entering the data as a part of the program, you can just run the program for new dates until and unless you want to change the location.

You may also replace the value stored in register 6 (steps 8 through 12, which is the angle from zenith being calculated) with other values, for example 96, 102 or 108 degrees to calculate civil, nautical and astronomical twilight times, respectively. If you enter a value less than 90 degrees, you may calculate the times at which the sun rises above and then later sets below 90 minus that value. (E.g., if you enter 50 degrees, the program will calculate the times at which the sun rises to and sets below 40 degrees elevation. This may be useful if you desire to limit your exposure to UV, for example.)

One of the subroutines may be used as a stand-alone program to calculate the number of days between two dates. Key in a date, press enter, key in other date, then press XEQ 02. (Key in the later date first if you want a positive result.)

Attached below is a wp34s emulator dat file that has the y.md version. The differences between the programs are fairly trivial, so you can easily edit to create the d.my or m.dy versions. (Changes are in step 2, and between steps 78 to 86.) If you have a crystal installed in your real wp34s (to facilitate reliable communication), and a communication cable, you can place the dat file in the appropriate folder, start the emulator, and upload to your real wp34s to save a lot of manual keying.

Version 1 - Input date in yyyy.mmdd format
Code:

Step   Instruction    Comments
001    LBL  'RS'      
002    y.md           set date mode
003    DEG            Set degrees mode (used throughout)
004    XEQ  01        Get days since first of year
005    STO 05         
006    5              Offest from UTC (-5 represents EST)
007    +/-            Offest from UTC (-5 represents EST)
008    STO 03         Local time offset from UTC
009    9              
010    0              
011    .              
012    5              
013    ->HR           90.83333333333333 entered for degrees from zenith
                      at Sunrise/sunset (fewer steps than direct entry)
014    STO 06         degrees from zenith for Sunrise.  May be changed if
                      twilight times or other solar elevation times are desired (e.g.
                      enter 50 to find times when sun is at 40 degrees altitude.)
015    3              Latitude
016    5              Latitude
017    .              Latitude
018    1              Latitude
019    2              Latitude
020    3              Latitude
021    4              Latitude
022    5              Latitude
023    STO 01         35.12345 for example (decimal)
024    9              Longitude
025    5              Longitude
026    .              Longitude
027    5              Longitude
028    4              Longitude
029    3              Longitude
030    2              Longitude
031    1              Longitude
032    +/-            Longitude
033    STO 02         -95.54321 for example (decimal)
034    1              15 Degrees per hour
035    5              15 Degrees per hour
036    STO 19         Store for later use
037    /              
038    STO 07         Longitude hour value (lngHour)
039    1              
040    8              Calculate approximate time for sunset
041    XEQ 05         
042    XEQ 06         
043    STO 15         Done calculating sunset.  Store the result
044    6              Calculate sunrise
045    XEQ 05         
046    RCL 17         Recall 360
047    X<>Y           
048    -              
049    XEQ 06         
050    RCL 15         Recall sunset.  Push sunrise to Y.
051    CL alpha       clear alpha register for new text message
052    'Ris'          
053    'e-S'          
054    'et'           
055    VIEWa          Display text
056    PSE 25         
057    CL alpha       clear alpha register for new text message
058    alphaRC# Y     copy Y register value to alpha register
059    VWalpha+ X     view alpha (sunrise) in dot-matrix, sunset time in X register.
060    STOP           
061    CPX STO Z      store sunrise and sunset times in Z and T
062    ->HR           convert sunrise time to decimal hours
063    x<>y           swap x and y
064    ->HR           convert sunset time to decimal hours
065    -              subtract for decimal hour day length
066    ->H.MS         convert day length to HMS
067    CL alpha       
068    'Day'          
069    ' Le'          
070    'ngt'          
071    'h'            
072    VWa+ X         Display text and day length
073    RTN            done
074    LBL 01         Calculate day of year given date
075    ENTER          
076    YEAR           
077    DEC X          
078    .              
079    1              
080    2              
081    3              
082    1              
083    +              
084    LBL  02        Given two dates (on stack) get days between
085    y.md           set date mode for delta-day entry point
086    D->J           julian day no. of input date
087    X<>Y           
088    D->J           julian day no. of last day of previous year
089    RCL- Y         days since first of year (or between dates)
090    RTN            
091    LBL 05         Subroutine for large common section
092    RCL- 07        
093    2              
094    4              enter 24
095    STO 20         Store for later use
096    /              
097    RCL+ 05        
098    STO 08         Approximate sunset time
099    .              
100    9              
101    8              
102    5              
103    6              enter 0.9856
104    x              
105    3              
106    .              
107    2              
108    8              
109    9              enter 3.289
110    -              
111    STO 09         Sun's mean anomaly
112    SIN            Calculate sun's true longitude
113    1              
114    .              
115    9              
116    1              
117    6              enter 1.916
118    x              
119    RCL+ 09        
120    2              
121    RCLx 09        
122    SIN            
123    .              
124    0              
125    2              enter 0.02
126    x              
127    +              
128    3              
129    RCLx 09        
130    SIN            
131    .              
132    0              
133    0              
134    0              
135    3              enter 0.0003
136    x              
137    +              
138    2              
139    8              
140    2              
141    .              
142    6              
143    3              
144    4              enter 282.634
145    +              
146    3              
147    6              
148    0              enter 360
149    STO 17         
150    MOD            
151    STO 10         Sun's true longitude
152    TAN            Calculate sun's Right Ascension
153    .              
154    9              
155    1              
156    7              
157    6              
158    4              enter 0.91764
159    x              
160    ATAN           
161    RCL 17         enter 360
162    MOD            
163    STO 11         Sun's Right Ascension
164    RCL 10         
165    9              
166    0              enter 90
167    STO 18         Store for later use
168    /              
169    FLOOR          
170    RCLx 18        Recall 90 and multiply
171    +              
172    RCL 11         
173    RCL/ 18        Recall 90 and divide
174    FLOOR          
175    RCLx 18        Recall 90 and multiply
176    -              
177    RCL/ 19        Recall 15 and divide
178    STO 11         Sun's Right Ascension converted into hours
179    RCL 10         
180    SIN            
181    .              
182    3              
183    9              
184    7              
185    8              
186    2              enter 0.39782
187    x              
188    STO 12         sinDec for sunset
189    ASIN           
190    COS            
191    STO 13         cosDec for sunset
192    RCL 06         
193    COS            
194    RCL 01         
195    SIN            
196    RCLx 12        
197    -              
198    RCL  01        
199    COS            
200    RCLx 13        
201    /              Sun's local Hour Angle (cosH)
202    ACOS           
203    RTN            
204    LBL 06         
205    RCL/ 19        Recall 19 and divide
206    RCL+ 11        
207    .              
208    0              
209    6              
210    5              
211    7              
212    1              enter 0.06571
213    RCLx 08        
214    -              
215    6              
216    .              
217    6              
218    2              
219    2              enter 6.622
220    -              
221    RCL 20         Recall 24
222    MOD            
223    RCL- 07        
224    RCL+ 03        
225    ->H.MS         
226    END

Version 2 - Input date in dd.mmyyyy format
Code:

Step   Instruction    Comments
001    LBL  'RS'      
002    d.my           set date mode
003    DEG            Set degrees mode (used throughout)
004    XEQ  01        Get days since first of year
005    STO 05         
006    5              Offest from UTC (-5 represents EST)
007    +/-            Offest from UTC (-5 represents EST)
008    STO 03         Local time offset from UTC
009    9              
010    0              
011    .              
012    5              
013    ->HR           90.83333333333333 entered for degrees from zenith
                      at Sunrise/sunset (fewer steps than direct entry)
014    STO 06         degrees from zenith for Sunrise.  May be changed if
                      twilight times or other solar elevation times are desired (e.g. enter
                      50 to find times when sun is at 40 degrees altitude.)
015    3              Latitude
016    5              Latitude
017    .              Latitude
018    1              Latitude
019    2              Latitude
020    3              Latitude
021    4              Latitude
022    5              Latitude
023    STO 01         35.12345 for example (decimal)
024    9              Longitude
025    5              Longitude
026    .              Longitude
027    5              Longitude
028    4              Longitude
029    3              Longitude
030    2              Longitude
031    1              Longitude
032    +/-            Longitude
033    STO 02         -95.54321 for example (decimal)
034    1              15 Degrees per hour
035    5              15 Degrees per hour
036    STO 19         Store for later use
037    /              
038    STO 07         Longitude hour value (lngHour)
039    1              
040    8              Calculate approximate time for sunset
041    XEQ 05         
042    XEQ 06         
043    STO 15         Done calculating sunset.  Store the result
044    6              Calculate sunrise
045    XEQ 05         
046    RCL 17         Recall 360
047    X<>Y           
048    -              
049    XEQ 06         
050    RCL 15         Recall sunset.  Push sunrise to Y.
051    CL alpha       clear alpha register for new text message
052    'Ris'          
053    'e-S'          
054    'et'           
055    VIEWa          Display text
056    PSE 25         
057    CL alpha       clear alpha register for new text message
058    alphaRC# Y     copy Y register value to alpha register
059    VWalpha+ X     view alpha (sunrise) in dot-matrix, sunset time in X register.
060    STOP           
061    CPX STO Z      store sunrise and sunset times in Z and T
062    ->HR           convert sunrise time to decimal hours
063    x<>y           swap x and y
064    ->HR           convert sunset time to decimal hours
065    -              subtract for decimal hour day length
066    ->H.MS         convert day length to HMS
067    CL alpha       
068    'Day'          
069    ' Le'          
070    'ngt'          
071    'h'            
072    VWa+ X         Display text and day length
073    RTN            done
074    LBL 01         Calculate day of year given date
075    ENTER          
076    YEAR           
077    DEC X          
078    SDR 6          
079    3              
080    1              
081    .              
082    1              
083    2              
084    +              
085    LBL  02        Given two dates (on stack) get days between
086    d.my           set date mode for delta-day entry point
087    D->J           julian day no. of input date
088    X<>Y           
089    D->J           julian day no. of last day of previous year
090    RCL- Y         days since first of year (or between dates)
091    RTN            
092    LBL 05         Subroutine for large common section
093    RCL- 07        
094    2              
095    4              enter 24
096    STO 20         Store for later use
097    /              
098    RCL+ 05        
099    STO 08         Approximate sunset time
100    .              
101    9              
102    8              
103    5              
104    6              enter 0.9856
105    x              
106    3              
107    .              
108    2              
109    8              
110    9              enter 3.289
111    -              
112    STO 09         Sun's mean anomaly
113    SIN            Calculate sun's true longitude
114    1              
115    .              
116    9              
117    1              
118    6              enter 1.916
119    x              
120    RCL+ 09        
121    2              
122    RCLx 09        
123    SIN            
124    .              
125    0              
126    2              enter 0.02
127    x              
128    +              
129    3              
130    RCLx 09        
131    SIN            
132    .              
133    0              
134    0              
135    0              
136    3              enter 0.0003
137    x              
138    +              
139    2              
140    8              
141    2              
142    .              
143    6              
144    3              
145    4              enter 282.634
146    +              
147    3              
148    6              
149    0              enter 360
150    STO 17         
151    MOD            
152    STO 10         Sun's true longitude
153    TAN            Calculate sun's Right Ascension
154    .              
155    9              
156    1              
157    7              
158    6              
159    4              enter 0.91764
160    x              
161    ATAN           
162    RCL 17         enter 360
163    MOD            
164    STO 11         Sun's Right Ascension
165    RCL 10         
166    9              
167    0              enter 90
168    STO 18         Store for later use
169    /              
170    FLOOR          
171    RCLx 18        Recall 90 and multiply
172    +              
173    RCL 11         
174    RCL/ 18        Recall 90 and divide
175    FLOOR          
176    RCLx 18        Recall 90 and multiply
177    -              
178    RCL/ 19        Recall 15 and divide
179    STO 11         Sun's Right Ascension converted into hours
180    RCL 10         
181    SIN            
182    .              
183    3              
184    9              
185    7              
186    8              
187    2              enter 0.39782
188    x              
189    STO 12         sinDec for sunset
190    ASIN           
191    COS            
192    STO 13         cosDec for sunset
193    RCL 06         
194    COS            
195    RCL 01         
196    SIN            
197    RCLx 12        
198    -              
199    RCL  01        
200    COS            
201    RCLx 13        
202    /              Sun's local Hour Angle (cosH)
203    ACOS           
204    RTN            
205    LBL 06         
206    RCL/ 19        Recall 19 and divide
207    RCL+ 11        
208    .              
209    0              
210    6              
211    5              
212    7              
213    1              enter 0.06571
214    RCLx 08        
215    -              
216    6              
217    .              
218    6              
219    2              
220    2              enter 6.622
221    -              
222    RCL 20         Recall 24
223    MOD            
224    RCL- 07        
225    RCL+ 03        
226    ->H.MS         
227    END

Version 3 - Input date in mm.ddyyyy format
Code:

Step   Instruction    Comments
001    LBL  'RS'      
002    m.dy           set date mode
003    DEG            Set degrees mode (used throughout)
004    XEQ  01        Get days since first of year
005    STO 05         
006    5              Offest from UTC (-5 represents EST)
007    +/-            Offest from UTC (-5 represents EST)
008    STO 03         Local time offset from UTC
009    9              
010    0              
011    .              
012    5              
013    ->HR           90.83333333333333 entered for degrees from zenith
                     at Sunrise/sunset (fewer steps than direct entry)
014    STO 06         degrees from zenith for Sunrise.  May be changed if
                     twilight times or other solar elevation times are desired (e.g. enter
                     50 to find times when sun is at 40 degrees altitude.)
015    3              Latitude
016    5              Latitude
017    .              Latitude
018    1              Latitude
019    2              Latitude
020    3              Latitude
021    4              Latitude
022    5              Latitude
023    STO 01         35.12345 for example (decimal)
024    9              Longitude
025    5              Longitude
026    .              Longitude
027    5              Longitude
028    4              Longitude
029    3              Longitude
030    2              Longitude
031    1              Longitude
032    +/-            Longitude
033    STO 02         -95.54321 for example (decimal)
034    1              15 Degrees per hour
035    5              15 Degrees per hour
036    STO 19         Store for later use
037    /              
038    STO 07         Longitude hour value (lngHour)
039    1              
040    8              Calculate approximate time for sunset
041    XEQ 05         
042    XEQ 06         
043    STO 15         Done calculating sunset.  Store the result
044    6              Calculate sunrise
045    XEQ 05         
046    RCL 17         Recall 360
047    X<>Y           
048    -              
049    XEQ 06         
050    RCL 15         Recall sunset.  Push sunrise to Y.
051    CL alpha       clear alpha register for new text message
052    'Ris'          
053    'e-S'          
054    'et'           
055    VIEWa          Display text
056    PSE 25         
057    CL alpha       clear alpha register for new text message
058    alphaRC# Y     copy Y register value to alpha register
059    VWalpha+ X     view alpha (sunrise) in dot-matrix, sunset time in X register.
060    STOP           
061    CPX STO Z      store sunrise and sunset times in Z and T
062    ->HR           convert sunrise time to decimal hours
063    x<>y           swap x and y
064    ->HR           convert sunset time to decimal hours
065    -              subtract for decimal hour day length
066    ->H.MS         convert day length to HMS
067    CL alpha       
068    'Day'          
069    ' Le'          
070    'ngt'          
071    'h'            
072    VWa+ X         Display text and day length
073    RTN            done
074    LBL 01         Calculate day of year given date
075    ENTER          
076    YEAR           
077    DEC X          
078    SDR 6          
079    1              
080    2              
081    .              
082    3              
083    1              
084    +              
085    LBL  02        Given two dates (on stack) get days between
086    m.dy           set date mode for delta-day entry point
087    D->J           julian day no. of input date
088    X<>Y           
089    D->J           julian day no. of last day of previous year
090    RCL- Y         days since first of year (or between dates)
091    RTN            
092    LBL 05         Subroutine for large common section
093    RCL- 07        
094    2              
095    4              enter 24
096    STO 20         Store for later use
097    /              
098    RCL+ 05        
099    STO 08         Approximate sunset time
100    .              
101    9              
102    8              
103    5              
104    6              enter 0.9856
105    x              
106    3              
107    .              
108    2              
109    8              
110    9              enter 3.289
111    -              
112    STO 09         Sun's mean anomaly
113    SIN            Calculate sun's true longitude
114    1              
115    .              
116    9              
117    1              
118    6              enter 1.916
119    x              
120    RCL+ 09        
121    2              
122    RCLx 09        
123    SIN            
124    .              
125    0              
126    2              enter 0.02
127    x              
128    +              
129    3              
130    RCLx 09        
131    SIN            
132    .              
133    0              
134    0              
135    0              
136    3              enter 0.0003
137    x              
138    +              
139    2              
140    8              
141    2              
142    .              
143    6              
144    3              
145    4              enter 282.634
146    +              
147    3              
148    6              
149    0              enter 360
150    STO 17         
151    MOD            
152    STO 10         Sun's true longitude
153    TAN            Calculate sun's Right Ascension
154    .              
155    9              
156    1              
157    7              
158    6              
159    4              enter 0.91764
160    x              
161    ATAN           
162    RCL 17         enter 360
163    MOD            
164    STO 11         Sun's Right Ascension
165    RCL 10         
166    9              
167    0              enter 90
168    STO 18         Store for later use
169    /              
170    FLOOR          
171    RCLx 18        Recall 90 and multiply
172    +              
173    RCL 11         
174    RCL/ 18        Recall 90 and divide
175    FLOOR          
176    RCLx 18        Recall 90 and multiply
177    -              
178    RCL/ 19        Recall 15 and divide
179    STO 11         Sun's Right Ascension converted into hours
180    RCL 10         
181    SIN            
182    .              
183    3              
184    9              
185    7              
186    8              
187    2              enter 0.39782
188    x              
189    STO 12         sinDec for sunset
190    ASIN           
191    COS            
192    STO 13         cosDec for sunset
193    RCL 06         
194    COS            
195    RCL 01         
196    SIN            
197    RCLx 12        
198    -              
199    RCL  01        
200    COS            
201    RCLx 13        
202    /              Sun's local Hour Angle (cosH)
203    ACOS           
204    RTN            
205    LBL 06         
206    RCL/ 19        Recall 19 and divide
207    RCL+ 11        
208    .              
209    0              
210    6              
211    5              
212    7              
213    1              enter 0.06571
214    RCLx 08        
215    -              
216    6              
217    .              
218    6              
219    2              
220    2              enter 6.622
221    -              
222    RCL 20         Recall 24
223    MOD            
224    RCL- 07        
225    RCL+ 03        
226    ->H.MS         
227    END

Register Usage:
Code:

01    Latitude
02    Longitude
03    Offset from UTC (local time)
04    Date 
05    Days from the beginning of the year.
06    Zenith
07    Longitude -> Hour Angle (lngHour)
08    Approximate time (t)
09    Sun's mean anomaly (M)
10    Sun's true longitude (L)
11    Right Ascension (RA)
12    Sun's declination (sinDec)
13    Sun's declination (cosDec)
14    Sun's local hour angle (H)
15    Sunset time
16    Year value
17    360
18    90
19    15
20    24
21    0.06571
22    6.622

**Update No. 1**
Based on Paul's and Dieter's ideas below, here is a single new version that will work in any date mode. (You must of course know what date mode the calculator is set to and enter the date accordingly.) I eliminated the accessible subroutine to calculate days between dates, since the built in wp34s ΔDAYS function can be used for that. The single program is now only 206 steps. The steps where time zone, longitude and latitude are enter have changed from above, but those are easy to figure. Otherwise, data entry, operation, and register usage remain the same, except 24 is no longer stored in register 20. I will change the wp34s.dat file to this version when I get the chance.
Code:

001    LBL  'RS'      
002    DEG            Set degrees mode (used throughout)
003    ENTER          Copy input date into Y, could use RCL X
004    YEAR           year of input date
005    DEC X          previous year
006    #12            enter 12
007    #31            enter 31
008    →DATE          create last day of previous year in current date mode.
009    X<>Y           
010    ΔDAYS          days from 1st of year
011    STO 05         
012    5              Offest from UTC (-5 represents EST)
013    +/-            Offest from UTC (-5 represents EST)
014    STO 03         Local time offset from UTC
015    9              
016    0              
017    .              
018    5              
019    ->HR           90.83333333333333 entered for degrees from zenith
                      at Sunrise/sunset (fewer steps than direct entry)
020    STO 06         degrees from zenith for Sunrise.  May be changed if
                      twilight times or other solar elevation times are desired (e.g.
                      enter 50 to find times when sun is at 40 degrees altitude.)
021    3              Latitude
022    5              Latitude
023    .              Latitude
024    1              Latitude
025    2              Latitude
026    3              Latitude
027    4              Latitude
028    5              Latitude
029    STO 01         35.12345 for example (decimal)
030    9              Longitude
031    0              Longitude
032    .              Longitude
033    5              Longitude
034    4              Longitude
035    3              Longitude
036    2              Longitude
037    1              Longitude
038    +/-            Longitude
039    STO 02         -90.54321 for example (decimal)
040    #015           15 Degrees per hour
041    STO 19         Store for later use
042    /              
043    STO 07         Longitude hour value (lngHour)
044    #018           
045    XEQ 05         Calculate approximate time for sunset
046    XEQ 06         
047    STO 15         Done calculating sunset.  Store the result
048    6              Calculate sunrise
049    XEQ 05         
050    RCL 17         Recall 360
051    RCL- Y         
052    XEQ 06         
053    RCL 15         Recall sunset.  Push sunrise to Y.
054    CL alpha       clear alpha register for new text message
055    'Ris'          
056    'e-S'          
057    'et'           
058    VIEWa          Display text
059    PSE 25         
060    CL alpha       clear alpha register for new text message
061    alphaRC# Y     copy Y register value to alpha register
062    VWalpha+ X     view alpha (sunrise) in dot-matrix, sunset time in X register.
063    STOP           
064    CPX STO Z      store sunrise and sunset times in Z and T
065    ->HR           convert sunrise time to decimal hours
066    x<>y           swap x and y
067    ->HR           convert sunset time to decimal hours
068    -              subtract for decimal hour day length
069    ->H.MS         convert day length to HMS
070    CL alpha       
071    'Day'          
072    ' Le'          
073    'ngt'          
074    'h'            
075    VWa+ X         Display text and day length
076    RTN            done
077    LBL 05         Subroutine for large common section
078    RCL- 07        
079    #024           enter 24
080    /              
081    RCL+ 05        
082    STO 08         Approximate sunset time
083    .              
084    9              
085    8              
086    5              
087    6              enter 0.9856
088    x              
089    3              
090    .              
091    2              
092    8              
093    9              enter 3.289
094    -              
095    STO 09         Sun's mean anomaly
096    SIN            Calculate sun's true longitude
097    1              
098    .              
099    9              
100    1              
101    6              enter 1.916
102    x              
103    RCL+ 09        
104    2              
105    RCLx 09        
106    SIN            
107    .              
108    0              
109    2              enter 0.02
110    x              
111    +              
112    3              
113    RCLx 09        
114    SIN            
115    3              
116    SDR 004        enter 0.0003
117    x              
118    +              
119    2              
120    8              
121    2              
122    .              
123    6              
124    3              
125    4              enter 282.634
126    +              
127    3              
128    6              
129    0              enter 360
130    STO 17         
131    MOD            
132    STO 10         Sun's true longitude
133    TAN            Calculate sun's Right Ascension
134    .              
135    9              
136    1              
137    7              
138    6              
139    4              enter 0.91764
140    x              
141    ATAN           
142    RCL 17         enter 360
143    MOD            
144    STO 11         Sun's Right Ascension
145    RCL 10         
146    #090           enter 90
147    STO 18         Store for later use
148    /              
149    FLOOR          
150    RCLx 18        Recall 90 and multiply
151    +              
152    RCL 11         
153    RCL/ 18        Recall 90 and divide
154    FLOOR          
155    RCLx 18        Recall 90 and multiply
156    -              
157    RCL/ 19        Recall 15 and divide
158    STO 11         Sun's Right Ascension converted into hours
159    RCL 10         
160    SIN            
161    .              
162    3              
163    9              
164    7              
165    8              
166    2              enter 0.39782
167    x              
168    STO 12         sinDec for sunset
169    ASIN           
170    COS            
171    STO 13         cosDec for sunset
172    RCL 06         
173    COS            
174    RCL 01         
175    SIN            
176    RCLx 12        
177    -              
178    RCL  01        
179    COS            
180    RCLx 13        
181    /              Sun's local Hour Angle (cosH)
182    ACOS           
183    RTN            
184    LBL 06         Subroutine for another common section
185    RCL/ 19        Recall 19 and divide
186    RCL+ 11        
187    .              
188    0              
189    6              
190    5              
191    7              
192    1              enter 0.06571
193    RCLx 08        
194    -              
195    6              
196    .              
197    6              
198    2              
199    2              enter 6.622
200    -              
201    #024           enter 24
202    MOD            
203    RCL- 07        
204    RCL+ 03        
205    ->H.MS         
206    END

Dave - My mind is going - I can feel it.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(34S) - Sunrise/Sunset - Jeff O. - 01-28-2015 08:08 PM
RE: WP 34S - Sunrise/Sunset - Kiwi Geoff - 02-09-2015, 10:06 AM
RE: WP 34S - Sunrise/Sunset - Jeff O. - 02-11-2015, 03:22 AM
RE: WP 34S - Sunrise/Sunset - Paul Dale - 02-09-2015, 09:13 PM
RE: WP 34S - Sunrise/Sunset - Dieter - 02-10-2015, 10:31 PM
RE: WP 34S - Sunrise/Sunset - Thomas_Sch - 02-11-2015, 07:48 AM
RE: WP 34S - Sunrise/Sunset - Dieter - 02-11-2015, 03:06 PM
RE: WP 34S - Sunrise/Sunset - Jeff O. - 02-11-2015, 05:49 PM
RE: WP 34S - Sunrise/Sunset - Dieter - 02-11-2015, 09:46 PM
RE: WP 34S - Sunrise/Sunset - Jeff O. - 02-11-2015, 08:03 PM
RE: WP 34S - Sunrise/Sunset - Paul Dale - 02-11-2015, 09:06 PM
RE: WP 34S - Sunrise/Sunset - Jeff O. - 02-13-2015, 12:19 AM
RE: WP 34S - Sunrise/Sunset - Dieter - 02-13-2015, 06:52 AM
RE: WP 34S - Sunrise/Sunset - Jeff O. - 02-13-2015, 02:19 PM
RE: WP 34S - Sunrise/Sunset - Dieter - 02-13-2015, 08:01 PM
RE: WP 34S - Sunrise/Sunset - Dieter - 02-15-2015, 07:57 PM
RE: WP 34S - Sunrise/Sunset - Jeff O. - 02-15-2015, 08:31 PM
RE: WP 34S - Sunrise/Sunset - Kiwi Geoff - 02-22-2015, 11:48 AM
RE: WP 34S - Sunrise/Sunset - Thomas_Sch - 02-11-2015, 06:09 PM
RE: WP 34S - Sunrise/Sunset - Kiwi Geoff - 02-21-2015, 02:17 AM
RE: WP 34S - Sunrise/Sunset - Dieter - 02-21-2015, 07:05 AM



User(s) browsing this thread: 1 Guest(s)