Program listing for RPN Sunrise/Sunset
10-14-2017, 04:10 PM
Post: #1
 Craig Bladow Senior Member Posts: 328 Joined: Apr 2016
Program listing for RPN Sunrise/Sunset
In the Articles section there is a listing for Program to calculate Sunrise/Sunset times. I came across a character in the program listing on line 68 (and others) that is puzzling. It looks like it should be an operator, but the section of listing below includes the other common arithmetic operators. Can someone explain what this is?

66 18
67 RCL 07
68 •
69 24
70 /
71 RCL 05
72 +
73 STO 08
74 .9856
75 x
76 3.289
77 •
78 STO 09

CC41 coming soon!
10-14-2017, 05:25 PM (This post was last modified: 10-14-2017 05:37 PM by Dieter.)
Post: #2
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: Program listing for RPN Sunrise/Sunset
(10-14-2017 04:10 PM)Craig Bladow Wrote:  In the Articles section there is a listing for Program to calculate Sunrise/Sunset times. I came across a character in the program listing on line 68 (and others) that is puzzling. It looks like it should be an operator, but the section of listing below includes the other common arithmetic operators. Can someone explain what this is?

If you look at the DOY routine it seems that this "•" must be a minus. This also matches line 68 where the difference between 6:00 resp. 18:00 h and the longitude divided by 15° (R07) is calculated. The same is true for the code around line 145 where, depending on flag 02, either a longitude or 360° minus this is calculated.

BTW there seems to be a similar problem with the 35s version. There are several lines with an "1." which also seems to stand for a "–" minus.

However I wonder why this "•" or "1." lines appear in the listing while elsewhere a simple "–" seems to work fine.

Dieter
10-14-2017, 05:44 PM
Post: #3
 Craig Bladow Senior Member Posts: 328 Joined: Apr 2016
RE: Program listing for RPN Sunrise/Sunset
Thanks Dieter, I'll give "minus" a try.

CC41 coming soon!
10-14-2017, 06:26 PM (This post was last modified: 10-14-2017 06:26 PM by SlideRule.)
Post: #4
 SlideRule Senior Member Posts: 1,324 Joined: Dec 2013
RE: Program listing for RPN Sunrise/Sunset
Craig
from the 33s listing for the equivalent section of program code:
C0029 FS? 0 If set use 18 for sunset calculation
C0030 18
C0031 RCL- G
C0032 24
C0033 /

so I'ld say Dieter nailed it.

BEST!
SlideRule
10-14-2017, 09:20 PM
Post: #5
 Craig Bladow Senior Member Posts: 328 Joined: Apr 2016
RE: Program listing for RPN Sunrise/Sunset
Thanks!

I found this also in the DOY program:

11 FS? 01 DMY mode

Should be

11 FS? 31 DMY mode

Still get a DATA ERROR, so need to do some more debugging.

CC41 coming soon!
10-15-2017, 05:16 PM (This post was last modified: 10-15-2017 06:05 PM by Dieter.)
Post: #6
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: Program listing for RPN Sunrise/Sunset
(10-14-2017 09:20 PM)Craig Bladow Wrote:  Still get a DATA ERROR, so need to do some more debugging.

FTR: I tried the HP41 version in V41 and it works just fine. The times for today exactly match those from a good online calculator.

However, I think the program can be improved. I also wonder if the FLOOR routine is really required. But I don't get any errors. At least not for my location and timezone. What values did you try?

Edit: The program calculates floor(R10/90) and floor(R11/90). Both R10 and R11 are the result of a mod 360 operation which always returns a value >= 0. So I think the complete FLOOR routine is obsolete and can be replaced with a simple INT command. And maybe the whole thing can be done even more elegantly with MOD.

Edit 2: I now have replaced the following lines of the original program...

Code:
 99    ATAN 100    360 101    MOD 102    STO  11 103    RCL  10 104    90 105    / 106    XEQ 'FLOOR    Floor function.  External program 107    90 108    x 109    + 110    RCL  11 111    90  112    /  113    XEQ 'FLOOR    Floor function.  External program 114    90 115    x  116    -      117    15 118    /      119    STO  11

...with this:

Code:
 99    ATAN 100    90 101    MOD 102    RCL  10 103    90 104    /      105    INT 106    90 107    x  108    + 109    15 110    / 111    STO  11

And it seems to work. But please do your own tests and report here if you find any cases where errors occur.

Dieter
10-15-2017, 10:15 PM
Post: #7
 Craig Bladow Senior Member Posts: 328 Joined: Apr 2016
RE: Program listing for RPN Sunrise/Sunset
Thanks for validating the program Dieter! It turns out I misplaced a decimal point in one of the constants so I am now getting good results. Once I save this to mag card(s) I will try your modifications. Since my longitude is > 90 degrees West it will be a good test of your changes.

CC41 coming soon!
10-16-2017, 02:10 AM
Post: #8
 Craig Bladow Senior Member Posts: 328 Joined: Apr 2016
RE: Program listing for RPN Sunrise/Sunset
Dieter, yes it works with your changes for my location. Thank you!

CC41 coming soon!
10-16-2017, 11:15 AM (This post was last modified: 10-16-2017 12:47 PM by Dieter.)
Post: #9
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: Program listing for RPN Sunrise/Sunset
(10-14-2017 09:20 PM)Craig Bladow Wrote:  I found this also in the DOY program:

11 FS? 01 DMY mode

Should be

11 FS? 31 DMY mode

BTW, there is no need to check flag 31 at all. Instead of Dec 31 simply count the DOY from 1 Jan, which is 1.01yyyy in either mode. ;-)
Here is a way to do so:

Code:
01  LBL"DOY" 02  100 03  SIGN 04  LastX 05  RCL Z 06  x 07  FRC 08  101 09  + 10  % 11  R^ 12  DDAYS 13  + 14  END

Edit: The original program uses data registers up to R15. Since some values are only stored and recalled once and can be held on the stack, the program can be modified so that it requires only registers up to R10. Maybe even less. And I got it down to less than 330 bytes (including the DOY routine) so that it will fit on three card tracks.

I don't know if the author of the original program, M. Joury, is still reading this forum, so I'm not sure if it's OK for him if I would post my "streamlined" version of his program. The implemented algorithm looks very accurate.

Dieter
Post: #10
 Craig Bladow Senior Member Posts: 328 Joined: Apr 2016
RE: Program listing for RPN Sunrise/Sunset
Dieter,
I think the updated version, with corrections of errors in the posting on the HP Articles portion of the old website, would be a valuable contribution to the HP-41c software library.

CC41 coming soon!
 « Next Oldest | Next Newest »

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